3

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?

edigu
  • 9,878
  • 5
  • 57
  • 80
Mike A
  • 39
  • 7

1 Answers1

5

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.

edigu
  • 9,878
  • 5
  • 57
  • 80