• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My template library, please share your thoughts.

So, i have my own template library which i use for months, it has been improved along the time and i could say it is very mature in this moment .
The reason i am writing this post is to present the features i have so far and get advices in what to improve, then release the library for CI community if this post proves that is useful.

Sample codes
Create a theme and use it
Will load the welcome.php file that is under /views/website/ folder.

Make the theme structure like :
-----pages (the views will stay here)
-----css (stylesheets here)
-----js (javascripts here)
-----images (images here)
Also in above exp, in the view file, the $images_url/$js_url/$css_url become available and points to the url of the theme folders.

Layouts or NOT ?
There's no real need to use special layouts files to have your header/footer/sidebars , continuing with the above example, you can do something as follows:
//In this case, doing :
echo $header . $sidebar . $footer; in the welcome_message file would brings these files in.
With layouts :
The above code, will look for a file in /views/website/layouts/default.php
which contains the $header/$footer/$sidebar which are loaded from partials AND $page_body which is actually the welcome_message file contents .

Right now we end up with a structure like :
Which i believe it's pretty okay .
Also, if you are using HMVC/MS, and you use the above structure under a certain module and you want resources(images/js/css) to be loaded from there you can tell the library to do so and insteand of loading the images/css/js from /views/theme it will load from

The library is pretty loose, you can organize your themes and their contents exactly how you want .

Managing Javascripts/Styleshets.
I have integrated options to use JSMin/CssMin + Phil's cache library for best performance.
A sample code :
In the above case, when loading the scripts, a string containing their names + their versions is created, then hashed with md5() and checked against the cache to see if it exists. If there is a cached version, that one will be served if not, the content of each file is read then all the files are groupped into one output writed to cache then served.
The generated url will be like
(Of course the assets controller needs to be created, but is very simple)
When using scripts version, the disadvantage is that after you modify a script, you must edit the version too.
If you pass set('use_js_version',FALSE) then instead of creating a md5() from the file names and versions, the md5 is created from the file contents therefore, everything is automated, and after you modify a script, the library will be self aware and will load the new version.The disadvantage is that, it takes time to read the files at every request.

Also you can minify and not group or group and not minify etc etc.
Same rules applies for stylesheets.

When loading scripts/styles in your controller, then in your views these would be available like
echo $page_scripts . $page_styles ;
The minify/groupping thing is something new and possible still needs some work, but for now i haven't encountered any problem and the bright side is that you can run php code inside without any problem though personally i don't really do it.

Some other aspects, the page titles are auto generated from controller/methods from the url, but also you can set it manually.You can add a title separator and pre/after title words , something like :
$this->template->set('before_title','My page is : ')
->set('after_title','pretty cool huh ?');
// Results in :
My page is : Controller :: Method :: Param 1 pretty cool huh ?

Description/Keywords can be set also via :
$data['description'] = 'BLAH';
$data['keywords'] = 'BLAH';

Plus, there are allot of features added (like a special config file with all the available config items or a special template helper or like any method accepts arrays or strings as params)
All the values passed via set() method could be also put in an array and initialized like :
$config = array('theme_path'=>'mytheme','pages_path'=>'pages'......[]);

So what do you believe about it ?

My only concern is that, maybe, using CssMin/JSMin is a bit too much for a template library and of course i am not sure how correct is to load resources like images/js/css from the views folder.

Nobody ?

I like that you don't have to use layouts if you don't want to. I just started using Phil's Template Library and I like it, but I think it might bug me that in every controller I have to set a layout and then build a view that is not a layout. How else is yours different than Phil's? It seems unusual that nobody ever made a comment here. Good luck.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.