In CodeIgniter, or core PHP; is there an equivalent of Rails's view partials and templates?
A partial would let me render another view fragment inside my view. I could have a common navbar.php
view that I could point to the inside my homepage.php
view. Templates would define the overall shell of an HTML page in one place, and let each view just fill in the body.
The closest thing I could find in the CodeIgniter documentation was Loading multiple views, where several views are rendered sequentially in the controller. It seems strange to be dictating the visual look of my page inside the controller. (i.e. to move the navbar my designer would have to edit the controller).
I've been searching on stackoverflow for a PHP way to accomplish this. I have found this page, which talks about simulating partials with ob_start. Is that the recommended approach inside CodeIgniter?
Try out Ocular - http://codeigniter.com/wiki/Ocular_Layout_Library/ - its a rails inspired templating library.
In PHP you'd use
include
You can check it, for partials and template
My recently released Template library works in this way.
That template library also plays nicely with my Dwoo implementation which will give your views much more power.
This is unfortunately not CodeIgniter specific at all, however I suggest you to have a look at Savant3 template system. It allows you to render the template to a string. Then you can simply stuck it to wherever you wish.
Maybe there's something like that in CodeIgniter?
I can think of a way to add a facility when rendering the view, to render the template, and then all the sub-template it contains.