CodeIgniter Forums
Layout question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: Layout question (/thread-73039.html)



Layout question - eincandela - 03-12-2019

Hello,

i'm a little suprised by the way the layout system in CI4 works (or maybe i didn't understand it correctly)

As far as i get it from the docs, the view file must declare the layout it is inserted into by:

<?= $this->extend('default') ?>
<?= $this->section('content') ?>
<h1>Hello World!</h1>
<?= $this->endSection() ?>

But why should it be the responsibility of the view file to know that info?
If i go the CI4 approach and want to reuse a page into another layout i have to duplicate it (or tweak it by passing a view name into a variable) + if i want to change the layout for a bunch of page, i have to modify all of them.

I can find my peace with that by tweaking it a little, but i don't see the pros of that design choice ? Any opinion welcomed Smile

Emmanuel


RE: Layout question - kilishan - 03-12-2019

This system matches what the Blade system in Laravel, Twigg Template Engine and others.

When you want to reuse portions you would consider the reused portion to be a partial view that doesn't extend anything. It would be called from a view that does extend a layout. This sounds weird at first blush but in the years I've built with the other engines mentioned, it's never been a problem. There is typically more stuff that surrounds the reusable content that is not reusable so it all works out.

Currently, I think there's a bug when trying to insert a view normally within a view so I need to revisit that this week, actually.

Of course - you have the option to continue not using layouts, also.


RE: Layout question - eincandela - 03-12-2019

Thank you for that detailed answer Smile

Still a little skeptical but i guess it's a matter of taste in the end.

I faced the include view bug and found a solution on this forum (by extending the View class and adding a renderPartial method, wich should be included in the core i think imo


RE: Layout question - kilishan - 03-12-2019

(03-12-2019, 03:18 PM)eincandela Wrote: Thank you for that detailed answer Smile

Still a little skeptical but i guess it's a matter of taste in the end.

I faced the include view  bug  and found a solution on this forum (by extending the View class and adding a renderPartial method, wich should be included in the core i think imo

Glad it helped. That new method is what I intended to do. A couple of other things need to be looked at also, but that's the first one to be done!