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

Additional layout layer

Is it possible to add an additional layer for rendering (with events or something else)? I mean not just like a partial but like a layout or the main view with its own $this->getContent(). Now the structure is like this:

<main view>
    <controller layout>
        <action view>
            <direct output from controller>
        </action view>
    </controller layout>
</main view>

But I want like this:

<main view>
    <some site's section layout>                |
        <controller layout>                     |
            <action view>                       |\
                <direct output from controller> | wrapping controller layout with custom layout
            </action view>                      |/
        </controller layout>                    |
    </some site's section layout>               |
</main view>

I'm interested in a way without cutting the custom layout into head/foot parts...

If you're using Volt. you can leverage Volt Template Inheritance.
Divide it into 3 block, header,middle, footer. some_site_section.volt extends main, and append/prepend some content in the header, middle, footer. controler.volt extends some_site_section and append some content in the header, middle, footer action.volt extends controller and append some content in the header, middle, footer



98.9k

You can use $this->setTemplateBefore('some-template') or $this->setTemplateAfter('some-template') to load a new template before/after the controller layout and the main layout: https://docs.phalcon.io/en/latest/reference/views.html#using-templates



32.5k

Ou... How can I miss that setTemplateBefore does exactly what I want =) Thanks!