Welcome Guest, Not a member yet? Register   Sign In
Layout question
#1

(This post was last modified: 03-12-2019, 02:12 PM by eincandela. Edit Reason: typo )

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
Reply
#2

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.
Reply
#3

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
Reply
#4

(03-12-2019, 02: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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB