zendframework / zend-expressive-zendviewrenderer

zend-view PhpRenderer integration for Expressive
BSD 3-Clause "New" or "Revised" License
11 stars 12 forks source link

Shared default params available in layout #41

Closed michalbundyra closed 6 years ago

michalbundyra commented 7 years ago

I think shared default parameters should be available in layout. Currently these are available only in template. I know that we can access them using:

$child = $this->viewModel()->getCurrent()->getChildren()[0];
echo $child->variableFromTemplate;

but it is not convenient at all...

I can't see any other way currently to set some layout params. Am I missing something?

The other solution for me will be possibility to set variables only for view, something like:

$renderer->addDefaultParam('layout-name', 'param-name', 'param-value');

Or maybe we should have both? Shared variables visible in layout directly (as I have done in PR) and possibility to set variables only for layout?

michalbundyra commented 7 years ago

I've checked how it works with twig (on zend-expressive). There in layout we have access to all variables - from template and shared.

jguittard commented 7 years ago

👍

geerteltink commented 7 years ago

I've checked how it works with twig (on zend-expressive). There in layout we have access to all variables - from template and shared.

Same for plates. You can set variables for a single template or all templates, including layouts.

mwillbanks commented 7 years ago

@webimpress actually i've done things like this in plates prior and other ways... the biggest question that I have when you start to explode the scope like this is how does this work with partials? More or less, how is the scope contained? AKA please add a test for scope containment :)

weierophinney commented 6 years ago

@mwillbanks The scope is contained as the variables are present:

In all other situations, you would need to inject them directly when calling partial(), render(), etc.

weierophinney commented 6 years ago

Thanks, @webimpress!