Powerful Theme helper to separate common views from themes |
[eluser]Blaze Boy[/eluser]
i have made a way to make your project themeable ... it consist only of one extension to loader, one config file, one helper ... and the themes directory it's one of the steps to the project i'm REmaking (vunsy) a website builder with codeigniter this is part of the docs Quote:why should i use themes i have made it and merge it to the vunsy project... and i have made the docs also download it from here [Download] installation 1- download vunsy2 from the link above(vunsy is not complete project yet, theme is complete) 2- copy themes directory 3- copy system/application/config/theme.php 4- copy system/application/helpers/theme_helper.php 5- copy system/application/library/MY_Loader.php 6- enjoy
[eluser]Blaze Boy[/eluser]
Themes the first thing you must know about themes is they are normal view files so you could load thems inside view and vice-versa. themes are located in a directory called 'themes' every theme is a folder like "default","glassy","sand"...etc why should i use themes the normal idea is to separate my views folder into some folders with theme names and then call the proper view file with the load->view function. $theme_name = "default"; Quote:$this->load->view($theme_name.'themefile');this will make you every time initialize the theme name variable ... the enhanced idea is to make the theme name as a config item and call it whenever you want. this is a very bad idea ... what if you want to separated themes from views, or you have a common view files for multiple themes, what if you want every theme to add an automatic doctype,javascript,style sheets,blocks inside blocks?, here we come with themes Configuration of themes themes has a config items inside Code: system/application/config/theme.php Code: Variable description default value Code: <?=theme_title()?> you can read the themes helper for more information Note:the themes helper is not auto loaded , remember to load it before using the tags How to load a theme file there is 2 way of loading the themes files, one specified for controllers, we extended the loader class with a function called theme just like the view function. Code: $this->load->theme('filename', array(), FALSE ); the second way is a function and it's in the theme helper, it is specified to deprecate the loader->theme() with a short syntax and to return the output by default. Code: theme_load('filename',array(),TRUE); create a main frame file the has the main page view in the default directory, Code: <?= theme_doctype(); ?> this will generate the page Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> you can use the theme_add() function to add css and javascript files, and meta,link,script blocks also are acceptable, when you use it it'll test the input to determine the type (CSS,JS,Meta) and add it the the proper array in config (without dupplication) , when the theme_head() function is called it'll grap the array and generate the code of charset,title,meta,css,js,block ... etc you can use the theme_add() function to add an array or nested arrays or strings, the file names could be relative to the site or to the theme (default) you can call another theme block from the theme file with the function Code: theme_load('blockname')
[eluser]Blaze Boy[/eluser]
Theme Helper Loading this Helper to load this helper use the code below Code: $this->load->helper('theme'); Code: theme_load( $file, $vars = array(), $return = TRUE) Code: theme_set( $theme ) Code: theme_img( $src, $theme=TRUE ) Code: theme_url( $themefile='' ) Code: theme_title( $title='html' ) Code: theme_sitename( $sitename ) Code: theme_pagetitle( $pagetitle ) Code: theme_add( $input, $theme=TRUE ) Code: theme_doctype() return the doctype line Code: theme_meta( $input ) add or return the meta block, you can use it to add the doctype line above your theme main style file Code: theme_css( $input, $theme=TRUE ) Code: theme_js( $input, $theme=TRUE ) Code: theme_head() Code: theme_foot()
[eluser]Blaze Boy[/eluser]
51 views and no even one comment ? don't you like it guys? any ideas?
[eluser]phpserver[/eluser]
Hi,i have tried it and i like it.Keep up the good work,we sure appreciate.
[eluser]subbu.genie[/eluser]
Hey, Great work. I was also looking for a similar situation. I was looking to integrate WP with CI, so that I could use the rich template library of WP with CI. Let me know if you have any idea. subbu
[eluser]Tominator[/eluser]
Hi man! I think this isn't very well solution. Why? 1, It's too hard for me Too many unneeded functions! 2, It's too complicated solution for me! Why I'm telling this. I've made my own solution, it's part of COMPER Template Parser (http://parser.comper.sk). But it works only with parser, so I've made better solution, which I'm still testing. But it's as easy as in Parser Tom.
|
Welcome Guest, Not a member yet? Register Sign In |