Welcome Guest, Not a member yet? Register   Sign In
Site-wide templates in CI
#1

[eluser]newbrand[/eluser]
Hi there,

I'm still wrapping my head around "typical" CI development norms. I've created a few basic registration, login, activation scripts etc. but now I'm trying to work out a way to create a templating engine that I can push to all the pages.

I've created a new library class called SiteTemplate and stored all my default methods, attributes etc. simple stuff like metatag handlers, JS modifiers etc.

Then I have a foot() and head() method which I plan to call before and after my $this->load->view() calls on each controller. The thing is that my site template will typically be modified by session or data actions thus I thought it would be best to specify the template specific functions in the controller as opposed to the view.

So in essence in each method in my classes I'd do soemthing like this:

Code:
$this->sitetemplate->head();
$this->load->view('register', $data);
$this->sitetemplate->foot();

I was hoping to get some feedback from the community on what the "norm" is to solve this problem. I'm trying to produce a light-weight solution without a template parser or anything like that. I'm not married to this method, esp. if there are much better ways out there.

:-)

Thanks in advance.

Dave
#2

[eluser]darkhouse[/eluser]
Based on what you have now, I think the simplest solution is to just do this

Code:
$this->load->view('register', $data);

And that register view would have this

Code:
$this->load->view('template_header');
//some content
$this->load->view('template_footer');

Now, I believe there are some template systems available here, though I haven't used any so I cannot make any recommendations.
#3

[eluser]Colin Williams[/eluser]
I went down this same road when I started and ended up with the Template Library you can peek at by following the link in my signature. It may or may not be what you need, but maybe seeing how it works will give you some ideas for your own solution
#4

[eluser]darkhouse[/eluser]
Colin, I looked into your template library a few days ago, on the surface it seems pretty cool. I think I actually downloaded it, but I haven't delved into it. I like the idea of content regions, and in fact I was considering using this for a CMS system I'm working on.
#5

[eluser]newbrand[/eluser]
Genius! I just implemented it. It's extremely flexible and does it pretty much the way I would have done it. WHY isn't this class included with the default CI distro. It SHOULD be!

I'm a bit worried that I'm going to run into bugs however. I'll go ahead and make use of it the maintenance aspects may prove to be a bit complicated.




Theme © iAndrew 2016 - Forum software by © MyBB