Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Shared layout doesnt work for me


in my module.php i set

$di['view'] = function(){

        $view = new \Phalcon\Mvc\View();

        $view->setViewsDir(__DIR__ . '/views/');

        $view->setLayoutsDir( '../../common' . DS . 'layouts');

        return $view;

what I want to happen is :

    include :
        - common/layouts/main.phtml ( where i have <head>head etc... )
        - module/views/index.phtml ( where i have "hi " )

but now i see only "hi"

is there anything else I need to configure ? or I should put this configuration elsewhere ?

It wouldn't look up a layout in common/layouts.main.phtml but in common/layouts/main.phtml


oops. that was a syntax error in my question, sorry i fix it now.

I will upgrade to 2.1 in 2 hours to test there. i saw you made some changes regarding views, paths and so on...

If it is still not working i will post a comment again

edited Sep '15

Ok i tested with 2.1 still the same...


public function registerServices(DiInterface $di)

    $config = require __DIR__ . "/config/config.php";

    //Registering a dispatcher
    $di->set('dispatcher', function () {
        $dispatcher = new \Phalcon\Mvc\Dispatcher();
        return $dispatcher;

    $di['view'] = function(){

        $view = new \Phalcon\Mvc\View();

        $view->setViewsDir(__DIR__ . '/views/');

        $view->setLayoutsDir( MODULES_DIR . 'common' . DS . 'layouts' . DS);

        return $view;


it only renders my /modules/Home/Views/Index.phtml

//edit my router for "/"

$router->add('/', array(
    'module'     => 'home',
    'controller' => 'index',
    'action'     => 'index'

edited Sep '15

Maybe you can attach an events manager to check what paths are being tried:


Thx., i will inform you once i got back home. Had to go out for 2 hr.

edited Sep '15

ok i managed to make it work, but now view/index.phtml is rendered before my main layout. ...

my common main.phtml

<!DOCTYPE html>
<html lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">



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

my index.phtml

<h1>Blog Title</h1>

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