ViewModel setTerminal not working properly

Hey Guys, i got a strange issue which i am not sure why it does occur.

So basicly i got this code in my controller:

$view = new ViewModel();
return $view;

Everything gets displayed correctly, but once i set


to not display the layout, it instead does not display the view.

Someone had this issue before?

Everything works like expected. Activate the error output, maybe there are other problems.

Everything works like expected.
I dont think so, in my ZF2 Version the


works like expected. I got this project in ZF2 and Laminas side by side. The same code but the
behaviour is different. In Zf2 setTerminal, does not allow the layout to be rendered, only the site content will be returned.

In laminas however, the behaviour is exactly the opposite. the site-content does not get displayed, only the layout.

i dont get any exceptions thrown nor do i get any errors :confused:

So i just tested it with getting the PhpRenderer in the Controller and echo the generated ViewModel (from above) and everything displayes correctly. So i think the problem might be in a configuration flag? or something like that?

the view manager setting in my module.config.php are like that:

'view_manager' => array(
		'display_not_found_reason' => true,
		'display_exceptions' => true,
		'exception_template' => 'error/index',
		'template_path_stack' => array(
			__DIR__ . '/../view',
		'template_map' => array(
			'layout/admin' => __DIR__ . '/../view/layout/layout.phtml',

There are no changes from zend-mvc or zend-view to laminas-mvc and laminas-view on this topic.

Nothing wrong here.

And yes, I have tested this myself:

  1. Install MVC Skeleton Application
    composer create-project -sdev laminas/laminas-mvc-skeleton my-application
  2. Update Controller Action
    namespace Application\Controller;
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\View\Model\ViewModel;
    class IndexController extends AbstractActionController
        public function indexAction()
            return (new ViewModel())->setTerminal(true);


<div class="jumbotron">
    <h1 class="display-4">Welcome to<br>Laminas MVC Skeleton Application</h1>

        Congratulations! You have successfully installed the
        <a href="" target="_blank">Laminas MVC Skeleton</a>.
        This skeleton can serve as a simple starting point for you to begin
        building your application on Laminas MVC.

    <hr class="my-4">

    <a class="btn btn-primary btn-lg" href="" target="_blank">Check Laminas on GitHub &raquo;</a>

<div class="card-deck">
    <div class="card">
        <h2 class="card-header">Follow Development</h2>
        <div class="card-body">
                Laminas Project is under active development. If you are
                interested in following the development, you can check
                <a href="">Laminas dev blog</a>,
                and <a href=";q=is:issue+org:laminas">Laminas issue tracker</a>
                (link requires a GitHub account). This is a great resource
                for staying up to date with the latest developments!

            <a class="btn btn-primary" href="" target="_blank">Laminas Project Portal &raquo;</a>

    <div class="card">
        <h2 class="card-header">Discover Modules</h2>
        <div class="card-body">
                Laminas MVC is a modular application.
                You can find multiple compatible modules on packagist.

            <a class="btn btn-primary" href="" target="_blank">Explore Laminas Modules &raquo;</a>

    <div class="card">
        <h2 class="card-header">Help &amp; Support</h2>
        <div class="card-body">
                If you need any help or support while developing with Laminas,
                you may reach us via <a href="">chat</a> or
                <a href="">forum</a>.
                We'd love to hear any questions or feedback you may have
                regarding any release.

            <a class="btn btn-primary" href="" target="_blank">Ping us on chat &raquo;</a>

Are there any listeners or something else in your application which can change or switch the layout?

Thank you very much @froschdesign, for pushing me into the right direction.

The Problem was, that the LayoutListener always set the setTemplate even if you told the ViewModel with setTerminate to not display the template.

A Pull-Request has been made and this problem should not occur in the future.


1 Like