CodeIgniter Forums
About layout rendering - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: About layout rendering (/showthread.php?tid=9026)

Pages: 1 2


About layout rendering - El Forum - 06-09-2008

[eluser]José Mota[/eluser]
I have a question for the developers of CI. As some other friends spoke, layout rendering is a major plus in good application design / development. I'm to ask when is layout rendering going to be integrated in CI, if it's not already integrated? If it is, please please tell me where that is!
I come from a Rails world like some if not most friends here and they sure loved Rails for that! (as well as some other things, of course xD)

Thanks. Cheers!


About layout rendering - El Forum - 06-09-2008

[eluser]Michael Wales[/eluser]
What, exactly, do you mean by layout rendering? I'm ashamed to admit I'm unfamiliar with the term.


About layout rendering - El Forum - 06-09-2008

[eluser]José Mota[/eluser]
Hey Michael!
In CI you can have this:
Code:
$this->load->view('viewFile');

Well, particularly in Ruby on Rails, the framework has this layout rendering, which means you have a master page and then you can have for example a div inside a page where the whole controller-generated content goes, so you don't have to build the same page template every time you build a different view with all the sidebars, headers, footers, etc.

Cheers!


About layout rendering - El Forum - 06-09-2008

[eluser]Matthew Pennell[/eluser]
In CI you can load multiple views, both in the controller or within another view (i.e. nested views). So your views do not have to contain the entire HTML file - headers, footers, etc. - you can break down your templates into chunks and load them as needed.

What you can't do is load a view and tell it which div to put the dynamic content into (at least in the controller).


About layout rendering - El Forum - 06-09-2008

[eluser]Pascal Kriete[/eluser]
Yeah, that's sort of a neat rails feature. In the same way that extending views in django is really nice.

There are easy ways to achieve this in CodeIgniter though. Like this:
Code:
<html>
bla bla...

<? $this->load->view($content);?>

<? $this->load->view($sidebar); ?>
</html>

There's your template file. Now you make a bunch of view partials, and pass their paths in as part of the data:
Code:
$data['content'] = 'member/login';
$data['sidebar'] = 'sidebar/search';

$this->load->view('template', $data);

So while the easy answer is no, it's not really a hard thing to add and there are plenty of community examples you can look at for inspiration.


About layout rendering - El Forum - 06-09-2008

[eluser]Michael Wales[/eluser]
Hmmm, I do this in CI, like so:

controller
Code:
$this->data->partial = 'users/add';
$this->load->view('_global/master', $this->data);

_global/master
Code:
<? $this->load->view('_global/header'); ?>
<? $this->load->view('_global/menu'); ?>
<? $this->load->view($partial); ?>
<? $this->load->view('_global/footer'); ?>



About layout rendering - El Forum - 06-09-2008

[eluser]José Mota[/eluser]
@michael, your approach is limitating for me, because the way partials are implemented depend on the controller, not the layout itself Smile

@inparo, a nice approach! Thank you.


About layout rendering - El Forum - 06-09-2008

[eluser]xwero[/eluser]
Did anyone say Template Inheritance Helper.


About layout rendering - El Forum - 06-09-2008

[eluser]stuffradio[/eluser]
Nope,
I don't believe anyone said that xwero Smile


About layout rendering - El Forum - 06-10-2008

[eluser]beemr[/eluser]
Template Inheritance is definitely a nice helper, but once I got into it, I found it a mismatch for CI, considering the immediacy and flexibility of its native view loader. I do love the Django concept of design blocks, but I think I've found a happy medium with a small library I wrote. I'll post it to the wiki.

Essentially, it'll let you call a view with a wrapper command and some data like so:

$data['wrap'] = '<span class="bigbox><span class="littlebox></span></span>';
$this->render->wrap('content',$data);

That'll produce the equivalent of <span class="bigbox"><span class="littlebox"><h1>Your content here...</h1></span></span>

If your 'wrap' data doesn't have a middle, it'll prefix or post-fix the tags as you might expect. I was aiming for the jQuery "wrap" function, if you're familiar with it.