Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Expressive: how to change layout using Zend View

Zend Expressive defaults to layout template when using Zend View. I note the addTemplate($template) function in PhpRenderer class but where and how to add an alternative template to layout?

In a middleware factory of an action, in the action itself, or somewhere else?

like image 745
Mike A Avatar asked Dec 11 '25 00:12

Mike A


1 Answers

Passing layout key to render() method of the renderer in data array seems like enough to switch layout just before returning the response.

For example:

class HomeAction
{
   public function __invoke($request, $response, $next)
   {
     $data = [
        'layout' => 'layout::default',
        // or 'layout::admin',
        // or 'layout::alternative',
     ];

     $body = $this->template->render('app::home', $data);

     return new HtmlResponse($body);
   }
}

I strongly recommend watching of repository and it's issue updates on github.

See #314 and #317.

like image 158
edigu Avatar answered Dec 12 '25 18:12

edigu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!