My template library, please share your thoughts. |
[eluser]Twisted1919[/eluser]
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. Code: $this->template->set('theme_path','website')->load('welcome_message',$data); Make the theme structure like : --views ---welcome -----pages (the views will stay here) -----css (stylesheets here) -----js (javascripts here) -----images (images here) Code: $this->template 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: Code: $this->template echo $header . $sidebar . $footer; in the welcome_message file would brings these files in. With layouts : Code: $this->template->set('layouts_path','layouts')->set('layout','default')->load('welcome_message'); 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 : Code: -----/views 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 /modules/module_name/views/theme 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 : Code: $this->template The generated url will be like http://site.url/assets/js/long-md5-hash-...d-versions. (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 Code: echo $page_scripts . $page_styles ; 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 : Code: $this->template->set('before_title','My page is : ') Description/Keywords can be set also via : Code: $this->template->set('description','BLAH')->set('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 : Code: $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.
[eluser]seanloving[/eluser]
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. |
Welcome Guest, Not a member yet? Register Sign In |