"Main template" |
[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?
[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
[eluser]Phil Sturgeon[/eluser]
The template lib in my signature does this. Its a bit... odd though Need to update that, will probably put the new version on in a few minutes if my internet stops crapping me around.
[eluser]mdavis1982[/eluser]
Hi... For this, I simply do: Code: $data['pageTemplate'] = 'path/to/the/partial/template'; 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!
[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); 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... |
Welcome Guest, Not a member yet? Register Sign In |