passing static content to the template |
[eluser]martin79[/eluser]
Hi, I am new to CI and although no being a PHP expert I got (some) things working real quick. I am trying to convert a static HTML website to CI. The basic template is the same through all pages, of course the content differs and there are some sidebars etc. on the subpages. There is no database, all the content is static like I already said. Now I am not sure whats the best way to pass all the static content from the controlers to the template? Would the right way be to create views (containing the actual content) for each content page and for all the sidebars and pass them to the template from the corresponding controller function? Do I need to use an additional template engine (like http://code.google.com/p/ocular/) or can I achieve this by using the basic CI install? Sorry, I know I am asking very basic, but Im just starting and still a bit lost. Thanks, cheers Martin
[eluser]ehicks727[/eluser]
Don't know if this will help, but I just posted a pretty in-depth 'pattern' (sort of) for using MVC in CI. http://ellislab.com/forums/viewthread/88904/#448932 For your particular situation, you'll want to add each static page as a route in the config/routes.php file. Then make a controller called 'static' or something like that. That way you don't have to create a controller for each static page. Also, you'd be helping yourself by putting all your views in a separate folder for the static pages. I typically have a folder called views/content or views/staticpages or anything like that. This keeps your views folder somewhat organized. Hope I helped you with at least some of your questions.
[eluser]martin79[/eluser]
Hi, thanks for the reply. What I wanted to say is that I have ONE master template that I use through my entire website. This master template has got "slots" that I need to fill up with static content. I was searching whats the best way to do this. Controler code: Code: $this->load->view ('master_template', array( I would set up several functions in my controler(s) and could load my views into the main template. Does this make sense? Dont know if the syntax is right... Cheers
[eluser]ehicks727[/eluser]
It would be easier to just load the content and sidebars in your template, not the controller. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> In your controller, set which file is the view for your sidebars and content like so Code: $this->data = array( Or something like that.
[eluser]Colin Williams[/eluser]
Wrote the Template library just for you! Check the link in my signature. |
Welcome Guest, Not a member yet? Register Sign In |