Zend Framework 2 - Layout and variable
layout, zend-framework2
Solution
Rob Allen has posted a great article about how to access view variables in another view model (e.g.: layout)
Basically the following code, placed inside your layout.phtml, will match your needs:
<?php
$children = $this->viewModel()->getCurrent()->getChildren();
$child = $children[0];
?>
<!-- some HTML -->
<?php echo $this->escape($child->myvar);?>
Problem
i have a layout used by all my views and i need to assign a variable from a controller to this layout , if i use this method on a controller it doesn't work : ``` public function indexAction() { return new ViewModel( array( 'testvar' => 'bla', )); } ``` anyone can help me ? thanks