Cockpit-HQ / Cockpit

Cockpit Core - Content Platform
https://getcockpit.com
Other
388 stars 47 forks source link

allow layout inheritance, added $viewVars #143

Closed raffaelj closed 1 year ago

raffaelj commented 1 year ago

Allow layout inheritance, e. g.:

Alternative syntax:

I also added $viewVars, which were dropped during the rewrite from v1 to v2.

The slots, that are passed to the initial call of render($view, $slots), are available in all parent/stacked layouts.

I added some more context in the discussion of #135.

Closes #135.

aheinze commented 1 year ago

The viewvars property was removed for a reason. The render method should be state- or contextless.

If you've a need for a global var storage I recommend to register an object that works as a storage.

The multi inheritance also adds additional complexity with possible edge cases also with the passed slots.

Thank you for your contribution but I have to put it on hold for now until I see a real gain for the project.

raffaelj commented 1 year ago

I did some research about template engines recently and I agree, that layout inheritance is error-prone. I still miss the @render('views:partials/file.php') functionality from Lexy in v1.

When I need a more powerful template engine, I'll pass my custom logic to Lexy or Twig and bypass the whole $app->render() method.