Hi there…
As discussed here: http://ellislab.com/forums/viewthread/49910/P45/#279320
I think that functions for linking css and js files should be broken out of the view library and put into a separate ‘page’ library.
I have written a basic page library. Features:
* Automatic linking of CSS and JS files (as per coolfactors idea in his view library)
* Ability to set title, description and keywords meta tags.
* Ability to pass values directly into the javascript environment (uses json_encode, so its PHP 5 or PHP 4 + the json extension)
* Ability to set javascript code to be executed in the window.onload function.
I will post the code in the next reply as its too long to include here!
Example usage:
Controller:
$this->page->set_title('My page');
$this->page->set_description('My page is all about me!');
$this->page->js_link('/js/my_javascript_file.js');
$this->page->js_link('/js/another_javascript_file.js');
$this->page->css_link('/css/my_css_file.css');
$this->page->css_link('/css/another_css_file.css');
$data = array('greet' => 'Hello world!', 'bye' => 'Goodbye!');
$this->page->js_set($data);
$this->page->js_init('alert(greet);');
In the view file:
<html>
<head>
<?php $this->page->do_head(); ?>
</head>
<body>
Content
</body>
</html>
Outputs:
<html>
<head>
<title>My page</title>
<meta name="description" content="My page is all about me!"/>
<link rel="stylesheet" type="text/css" media="all" href="/css/my_css_file.css" />
<link rel="stylesheet" type="text/css" media="all" href="/css/another_css_file.css" />
<script type="text/javascript" src="/js/my_javascript_file.js"></script>
<script type="text/javascript" src="/js/another_javascript_file.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var greet="Hello world!";
var bye="Goodbye!";
/* ]]> */
</script>
<script type="text/javascript">
/* <![CDATA[ */
window.onload=function(){
alert(greet);
}
/* ]]> */
</script>
</head>
<body>
Content
</body>
</html>
