Hi,
I am still struggling about the best ZF2 way to render a footer and a
sidebar within a layout.
I found this example within Robs Test App:
------------------------------------------------------------------------
public function addAnotherViewModelToLayoutAction()
{
// Use an alternative layout
$layoutViewModel = $this->layout();
$layoutViewModel->setTemplate('layout/another');
// add an additional layout to the root view model (layout)
$sidebar = new ViewModel();
$sidebar->setTemplate('layout/footer_one');
$layoutViewModel->addChild($sidebar, 'footer');
return new ViewModel();
}
------------------------------------------------------------------------
Looks easy at first glance. But I don't want to repeat this code in
every action method I have. This should be done application wide.
Besides the rendering of such a footer or sidebar template I also want
to access my service class to grab some data and pass it to footer and
sidebar for output.
Should I write my own listener for the 'render' event?
Should I write a controller plugin that is processed automatically?
Or should I write a view helper that is able to access my service class
for the data?
Or is there another solution, maybe the best practice solution?
Or should I use the InjectTemplateListener which Marco suggested to me a
couple of weeks ago? If yes, has someone an example for it?
https://github.com/zendframework/zf2/blob/master/library/Zend/Mvc/View/Http/InjectTemplateListener.php
Thanks for your ideas?
Best regards,
Ralf
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]