We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to make a default layout for all modules' views?

This is what I am trying to do:

views module1 controller1 action1.tpl controller2 action2.tpl index.tpl module2 controller1 action1.tpl controller2 action2.tpl index.tpl

I want module2 to get the index.tpl from the parent directory automatically. But I cannot do that when I am writing:

public function registerServices($di) {
    // dispatcher here

    $view = $di->get('view');

because this way, the views directory root is changed to module2 and now it has no idea about the parent. What can I do to achieve that and have a unified layout throughout the application if the module doesn't have its own layout.


i am not sure i understand what you meant. but there is

setMainView method on the view object

edited Jun '14

The main view is the file name relative to the views directory, here is the directory structure that I am trying to build:

                /index.volt <-- I want this view to be the main layout

edited Nov '14

Try using $view->setMainView("../index.volt");, I believe that should do what you need.