We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 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(); ?>

and

<!-- app/views/index.phtml -->
<html>
    <head>
        <title>Example</title>
    </head>
    <body>

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

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

    </body>
</html>

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



5.1k

Hello

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