We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Main layout rendered twice

Hi!

Please help me to solve problem with main layout file rendered twice.

I have /views/base.html as Main Layout wich I set using $view->setMainView('base'); Also I have /views/signin/login.html

Base.html is:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    ...
</head>
<body>

<?php echo $this->getContent() ?>

</body>
</html>

login.html is:

<form>
LOGIN FORM HERE
</form>

When I use "pick" everything seems to be fine.

$this->view->pick('signin/login');

But if automatic mode base.html rendered twice. I tried to Google for 3 hours with no success :(

Thank in advance!

Thank you, Izo. I inspected that repo and unfortunately din't find the solution. Maybe I can clarify the situation by telling that I use all 3 view layers in my App: Main Layout, Controller Layout, Action View. This is my initialization code for View in Application.php:

    protected function _registerView()
    {
        $di = $this->getDI();
        $config = $di->get('config');

        $di->set('view', function() use ($di, $config) {
            $view = new \Phalcon\Mvc\View();

            $view->setViewsDir(VIEWS . '/views/');
            $view->setLayoutsDir(VIEWS . '/views/layouts/');
            $view->setMainView('base');

            return $view;
        }, true);
    }


85.5k
edited Nov '16

here is my view servise


$di->set('view', function () {
    $config = $this->getConfig();

    $view = new View();

    $view->setViewsDir($config->application->viewsDir);
    $view->setTemplateAfter('main')
        ->setLayoutsDir($config->application->layoutDir)
        ->setPartialsDir($config->application->particialDir);

    $view->registerEngines([
        '.volt' => function ($view) {
            $config = $this->getConfig();

            $volt = new VoltEngine($view, $this);

            $volt->setOptions([
                'compiledPath' => $config->application->cacheDir . 'volt/',
                'compiledSeparator' => '_'
            ]);

            return $volt;
        }
    ]);

    return $view;
}, true);

in controllers i do nothing

'viewsDir'       => APP_PATH . '/views/',
'layoutDir'      => APP_PATH . '/layouts/',
'particialDir'   => APP_PATH . '/particials/',