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

Phalcon Layouts


I'm having problem with using layouts.

According to docs -https://docs.phalcon.io/en/latest/reference/views.html - there is hierarchical rendering. So i've used skeleton application which outputs hello world, and created dir Layouts in views, then put there index.phtml. But its content is not rendered. What's more, if i remove index.phml from views dir, nothing is rendered. Any clues?


Inside of your app -> views -> layouts directory, create your layout file... In this case, assume layout.phtml.

Inside of your "MyController" controller, make sure you have this:

    public function initialize() {

This will tell the controller to use the layout template.

Inside of your layout file, make sure you have this where you want the included content to be placed:

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

Then when you resolve a route, you'll do this:

        'controller' => 'mycontroller',
        'action' => 'somepath'

Then inside of your "MyController" controller you'll do this:

    public function somepathAction() {

At this point you'll have a file in app->views->some-path.phtml (or volt or whatever) that will have the content you want rendered inside of the layout.