Templating with Code Igniter |
[eluser]Unknown[/eluser]
I'm very new to Code Igniter, so any help or suggestions here is appreciated. I know I'm being a little picky, but I would rather not have to load my header, load my content view, and then load my footer every time I want to render a page on my site. I typically use a "master page" approach, where I have one master template that just include()s the other views. I find that this approach makes it a lot easier to keep my template organized, rather than splitting up my XHTML templates into header/footer sections Can anyone help me brainstorm some ways to accomplish a master page approach? I was thinking of possibly creating a class that extends Controller (myController for example) and somehow have it call include header and include footer. However, if I make a class that extends myController, I need myController to first call include header, then call whatever is in the extending class's index(), then call include footer. So yeah, hopefully that makes sense. It's a little late and I've been battling with my laptop all day so I'm pretty tired. Again, any ideas are very much appreciated. Thanks! Mike edit: after searching the forums I've stumbled across http://williamsconcepts.com/ci/codeignit...index.html, and it looks very promising.
[eluser]Sumon[/eluser]
I think there are one more way you can implement master page concept without CI template. First of all lets consider a view file. It have header footer and body where body container varies for controller and functions. Now lets say we first assign body container value into a variable. Code: $data['main_container_view']=$this->load->view("member/registration_page"); Code: $this->load->view("masterpage/not_logged_in" , $data);
[eluser]fesweb[/eluser]
Here's a simplified version of what I've just (finally) arrived at... Master template (views/templates/master_page): Code: <html> In whatever controller you are working with: Code: // get some data This is undocumented on the "Views" page of the user guide, but I learned (afterward) that it's covered on the loader page. You can do this with as many sections as you like, and load different master pages depending on your needs (ex: templates/master_2column, templates/master_3column, etc). Master: Code: <html> Code: $data = $some_query->result(); Hope that helps.
[eluser]Filip_vh[/eluser]
Hi! Well it worked out and it is what I'm looking for. Unfortunately it seems to not load my css anymore now. Any idea's on that? probably cause my css and images are located in my templates folder. My views can't find them I think?
[eluser]xwero[/eluser]
Filip_vh you probably using a relative url? because views can be reused in other places it's best to use an absolute url.
[eluser]Filip_vh[/eluser]
Yep, I just found it myself as well but thanks. I looked at the page source and realised my stupidity... The css and images were in the templates folder while they should be in a different. Only problem is that now it doesn't recognize my '$content' in my master page while I am passing it through. ah well... I'll figure that one out as well soon enough. probably something stupid anyway ... If I can't find it ... I'll be back Edit: I solved it. Thanks for the help guys!
[eluser]Bramme[/eluser]
Personally, I love the template library (by Colin Williams) for this kind of thing. http://ellislab.com/forums/viewthread/88452/ |
Welcome Guest, Not a member yet? Register Sign In |