Search code examples
phplayoutmezzio

Layout no render on some actions in Zend Expressive?


Is it possible to set layout no render in one Action (or set of Actions)?

As I know I can set default layout in config, which will render on every page. I can change it in Action bay passing the 'layout' variable with value, but is it possible to not render layout at all?

class IndexAction
{
    private $template;

    public function __construct(Template $template){ ... }

    public function __invoke($request, $response, $next = null)
    {
        if(!$request->hasHeader('X-Requested-With')){
            $data = ['layout' => 'new\layout']; //change default layout to new one
        }
        else{
            $data = ['layout' => false]; //I need only to return view ?
        }

        return new HtmlResponse($this->template->render(
            'web::index', $data
        ));
    }
}

Solution

  • Now it's available, just set layout = false

        return new HtmlResponse($this->template->render(
            'web::index', 
            ['layout' => false]
        ));