问题描述:

each one of my pages shares the common.css stylesheet but then nearly every other page has its own custom stylesheet and this is the same for javascript files.

My main template file is in this sort of format (obviously the real one has more html in it):

<html>

<head>

<title><?php echo $this->data['title']; ?></title>

</head>

<body>

<?php echo $this->data['content']; ?>

</body>

I was thinking of doing it this way:

When I create the view object in the controller I could add the required files (in an array) to the view object so then they could be accessed in the main template like $this->data['css'] and $this->data['javascript'] and I could loop through the arrays in the main template to output them in the <head> of the page.

Is this an okay way to do it or is it breaking some rules or bad practice? Thanks.

网友答案:

It is totally okay, though I advice you to write yourself a asset() method in order to prepend your basepath before filename [e.g. http://yoursite.com/web/] so your code is more portable an deploying is easier.

As Fluffeh said consider compressing your whole styles in a single file for better performance - check YUI compressor for example.

相关阅读:
Top