Welcome Guest, Not a member yet? Register   Sign In
Page library
#1

[eluser]Al James[/eluser]
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:

Code:
$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:

Code:
<html>
<head>

<?php $this->page->do_head(); ?>

</head>
<body>
Content
</body>
</html>

Outputs:

Code:
<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>


Messages In This Thread
Page library - by El Forum - 07-19-2007, 02:57 AM
Page library - by El Forum - 07-19-2007, 03:00 AM
Page library - by El Forum - 12-10-2007, 02:50 PM
Page library - by El Forum - 12-10-2007, 03:06 PM
Page library - by El Forum - 12-10-2007, 03:34 PM
Page library - by El Forum - 12-10-2007, 03:55 PM
Page library - by El Forum - 12-10-2007, 04:54 PM
Page library - by El Forum - 12-10-2007, 07:10 PM
Page library - by El Forum - 12-13-2007, 08:24 AM
Page library - by El Forum - 12-13-2007, 08:38 AM
Page library - by El Forum - 04-20-2011, 08:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB