Master templating with CI |
[eluser]gnomixa[/eluser]
Hi guys (and gals)! I am a noob to CI, I read the user documentation and did the beginner tutorial to get the basics. However, I still have a question before I proceed with CI (i am still evaluating it for my next project). I am sure this has been asked before, but after an hour on google I couldn't find an answer to this. I want an easy and logical way to maintain the same look for an entire web site. So far the only way I have seen it being done is something like this: <?php $this->load->view('header'); $this->load->view('sidebar'); $this->load->view('content'); $this->load->view('footer'); ?> from my understanding this means I have to put this code in EVERY controller. I was wondering if there is a way to maintain the same look on the site w/ minimal code repetition. Perhaps derive a my_controller that will encapsulate it... CI experts, what's the best way? Thanks in advance
[eluser]umefarooq[/eluser]
hi yes there is way just have look on this template library it will solve you problem here is the link http://www.williamsconcepts.com/ci/codei...late/?v141
[eluser]Armchair Samurai[/eluser]
While template libraries are nice, I find they are often overkill for many projects. If you don't need overly complex rules for templating, try something like this: Create a view file called something like template.php, which will contain code something like this: Code: <?php Code: $this->load->vars(array(
[eluser]Armchair Samurai[/eluser]
If it's good enough for Rick Ellis, it's good enough for me.
[eluser]gnomixa[/eluser]
This method reminds me of the times when my server code was embedded in my html. Of course, CI is way more organized, but I would still rather separate my code as much as I can. I don't mind echoing variables, but is there a way to avoid calling functions in my views? (and loading another view is calling a function) I am interested to know what options I have as far as templating goes.....
[eluser]The Wizard[/eluser]
hello, i use a very similear approach. i have master-.... php's which load the "header" "main" and "footer". just like you explained it, and off course, they do it for which theme is actually loaded.
[eluser]mello.capinpin[/eluser]
check this simple template i wrote.. might help you. http://ellislab.com/forums/viewthread/94035/
[eluser]gyo[/eluser]
You can load the different views directly in your master template using the same code: <?=$this->load->view('header')?> I know short tags are deprecated but I'll use them as long as they can be enabled in the php.ini... ![]() |
Welcome Guest, Not a member yet? Register Sign In |