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

Volt multiple inheritance just doesn't work

I have to tell you thant Volt Multiple Inheritance just doesn't work like explained in the documentation. https://docs.phalcon.io/en/latest/reference/volt.html#template-inheritance

Example :


// index.volt 
<!DOCTYPE html>

 <html>

 <head>

 ...
 </head>

 <body>

 {% block content %}  // want to retrieve from child layout.volt{% endblock %}

 </body>

 <div class="footer">

 ... some code

</div>

 </body>

 </html>
 // layout.volt 
 {% extends "index.volt" %}

 {% block content %}

 ... some code

  // want to retrieve from child view.volt

 ... some code

 {% endblock %}

 {% block javascript %}

 // want to retrieve from child view.volt

 {% endblock %}
 // view.volt

 {% extends "layout.volt %}

 {% block content %}

 ... some code

 {% endblock %}

 {% block javascript %}

 ... some code

 {% endblock %}

Could you explain me why it doesn't work ? It is supposed to work regarding to Phalcon doc.



33.8k
  1. You cannot add {% block javascript %} in a child template, because it doesn't existe in the primary parent template (said in other way, you cannot add new content blocks in child templates).
  2. You have to use {{ super() }} when retrieving content from the parent template.
  3. When you extend, you put the content into the child template, not the parent template. I think you should use include for the opossite effect (https://docs.phalcon.io/es/latest/reference/volt.html#view-integration). The above rules applies the same way for this (except for the second one).