Welcome Guest, Not a member yet? Register   Sign In
"Main template"

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

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 Wink

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


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

Then, in my site.php view file, I have:

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:

$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...

Theme © iAndrew 2016 - Forum software by © MyBB