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

Question on views hierarchy

According to the Hierarchical Rendering here, content of app/views/layouts/posts.phtml should appear when loading /posts URI (https://localhost/myapp/posts). So I tested the example given in the documentation:

<!-- app/views/layouts/posts.phtml -->

<h2>This is the "posts" controller layout!</h2>

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


<!-- app/views/index.phtml -->

        <h1>This is main layout!</h1>

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


and it works, so great.

But I am wondering why do we have to use <?php echo $this->getContent(); ?> to make the "hierarchy system" actually work (if one remove it, it does not work anymore), what the point of having an "hardcoded" system if one have to add this code ?

Thank you



I think it's to specify where you want to place the content you can place many html elements before and after contents This ensures maximum flexibility