CodeIgniter Forums
"Main template" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: "Main template" (/showthread.php?tid=5215)



"Main template" - El Forum - 01-11-2008

[eluser]Unknown[/eluser]
How would one implement a main template that all controllers could echo data to, instead of having a different view for every page?


"Main template" - El Forum - 01-11-2008

[eluser]tonanbarbarian[/eluser]
Looks like you need a layout library
lots of posts about those as well as wiki entries

Here is one of my previous posts on the topic - which has links to wiki entries

Creating a template in CodeIgniter



"Main template" - El Forum - 01-12-2008

[eluser]Phil Sturgeon[/eluser]
The template lib in my signature does this. Its a bit... odd though Wink

Need to update that, will probably put the new version on in a few minutes if my internet stops crapping me around.


"Main template" - El Forum - 01-13-2008

[eluser]mdavis1982[/eluser]
Hi...

For this, I simply do:
Code:
$data['pageTemplate'] = 'path/to/the/partial/template';
$this->load->view('site', $data);

Then, in my site.php view file, I have:
Code:
$this->load->view($pageTemplate);

Seems to work a treat for me and doesn't need me to get bogged down installing more helpers, etc.

Try it out!


"Main template" - El Forum - 01-13-2008

[eluser]Phil Sturgeon[/eluser]
Of course it can be done as simply as that. If you really boild my library down it comes to the exact same method, which is:

Code:
$data['page_content'] = $this->load->view($file_name, $data, TRUE);
$this->load->view('layout', $data);

Although most will look at libraries like mine or YAST and think they are overcomplicated bloat-code, you will find as you start to develop more applications that you need something extra. For example, you need a way to easily wrap another view around your sub-page and the main layout, or you need a way to dynamically work out which folder the file is in, or create navigation on the fly.

Automatic breadcrumb and title generation are all extra fun added to the mix. Support for modular seperation too!

Id ignore my error message and info methods though, those are still not properly thought through...