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 - How to multiple inheritance

Hi please help i cant make it work.

I wanna do something like this :

  • A main layout file
  • A main "admin" layout file which inherit the main layout file, with the bonus some admin css and js file
  • A simple action file like admin/login admin/dashboard which extend admin layout

I have views/index.volt as main layout :


<html>
<head>
{% block header_css %}{% endblock %}
</head>
<body>
{% block content %}*text 1*{% endblock %}
</body>
</html>

I have views/layouts/admin.volt as admin layout


{% extends "index.volt" %}
{% block header_css %} new css {% endblock %}

{% block content %}* text 2* {% endblock %}

I have views/admin/login.volt as action file


{% extends "layouts/admin.volt" %}
{% block content %} *text 3 *{% endblock %}

And my controller :


public function loginAction(){
        $this->view->pick('admin/login');    
    }

And what i see in browser is content of admin.volt which is text 2 not text 3 is what i want



3.9k
edited Sep '17

The extender function not work with more then one level. I strongly recommend you make use of partial inclusions, especially in external files type js and css rather than try to do so many extends. It will keep your code clean and easy to repair.

view-integration-partial-vs-include