Volt - templates extending

755 views Asked by At

I use Phalcon PHP and Volt Template Engine and I got problem with templates extending. This is what i want to do:

Base template:

// index.volt

<!DOCTYPE html>
<head> [...] </head>
<body>
  <div>
    [...]
    <div class="row">

      <div class="col-sm-2"> {% block leftBlock %}{% endblock %} </div>

      <div class="col-sm-8"> 
        {% block content %} {{ content() }} {% endblock %} 
      </div>

      <div class="col-sm-2"> {% block rightBlock %}{% endblock %} </div>
    </div>
  </div>

[...]

Then controller's template:

// layouts/controller.volt

{% block leftBlock %}
  {{ partial("menus/fooMenu") }}
{% endblock %}

{% block content %}
  {{ content() }}
{% endblock %}

I'd like to replace content from leftBlock with menu, but i when i do this i got menu in content block. I'm aware it's because of using content() method but i can't find another way to use templating.

When i put {% extends "index.volt" %} at the beginning of controller.volt I got whole content form index.volt in controller view including even head tag.

What is proper way to extending templates in that way?

1

There are 1 answers

0
Sergiy On

i'm afraid you confused layout and template concept. This is slightly different things in phalcon.

You should revise https://docs.phalconphp.com/ru/latest/reference/views.html#rendering-levels page. Especially rendering levels chapter to achieve what you want.