https://github.com/zendframework/zend-expressive-twigrenderer/issues/24
Based on this question, I want to pass a variable to layout from an Action How can I try to do that?
$toast = [
'level'=>'info',
'msg' =>'rafael',
'url' => null
];
$this->template->addDefaultParam(Template\TemplateRendererInterface::TEMPLATE_ALL,'toast',$this->toastrMessenger->show($toast));
return new HtmlResponse($this->template->render('contentpages::contact',$data));
on my layout/default.phtml
<?php
if ( isset($this->toast) ){
echo $this->toast;
}
?>
</body>
</html>
Did you try "addDefaultParam" method? signeture is;
public function addDefaultParam($templateName, $param, $value)
and you can set star (*)
as $templateName
(see TemplateRendererInterface::TEMPLATE_ALL) so i think layout can read it.
You can read about it on documentation. Let me know if its working.