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 about volt template

project folder structure:

/app
  /controllers
    ServiceController.php
  /views
    /service
      about.volt
    index.volt
/public
  /css
  index.php
{# index.volt #}
<!DOCTYPE html>
<html>
    <head>
        {% block head %}{% endblock %}
    </head>
    <body>
{% block content %}{% endblock %}
    </body>
</html>
{# about.volt #}
{% block head %}<... head section here ...>{% endblock %}
{% block content %}<... simple html code here ...>{% endblock %}

but looks like it does not work, event if I add {% extends "index.volt" %} to about.volt. And when I change the 2 files like

{# index.volt #}
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
{{ content() }}
    </body>
</html>
{# about.volt #}
<... head section here ...>
<... simple html code here ...>

the page can be shown on browser, but that is not what I want, any idea? thx.



1.5k
Accepted
answer
edited Mar '14

Hi @miao606, I also had this problem until yesterday.

In this forum issue I explain my solution Volt block not working with hierarchical view rendering

Try to remove {{ content() }} from the main template, add {% extends "index.volt" %} in the top of the about.volt file and set the view render level to LEVELACTIONVIEW (Ex.: $view->setRenderLevel(\Phalcon\Mvc\View::LEVELACTIONVIEW)).

After these changes, remove the volt render cache files to test that the main template changes works fine.

I hope it works for you.



29.1k

It works for me, thanks Tino.