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

Embedding blocks into other blocks is not supported

Hi folks,

I developed a Volt template and I intend to use it such as a standard for the others. There is an example of my code below:

{# LOCKED MODE #}
{% if session.get('locked_mode', true) is not empty and session.get('locked_mode', true) is true %}
    {{ partial('locked_mode_view') }}
{# UNLOCKED MODE #}
{% else %}
<div class="row">
    {{ partial('unlocked_mode_view') }}

    {% block content %}
        {{ partial('unlocked_mode_content') }}
    {% endblock %}
</div>
{% endif %}

While it was compiling, the compiler shown this error:

Embedding blocks into other blocks is not supported in...

I didn't understand this error. What can I do in this situation?

edited Jan '19

You must refactor your template.

See this issue: https://github.com/phalcon/cphalcon/issues/329

Hello @lajosbencz,

Thanks for your reply, but I still have not understood the reason for this error. Is it because the Volt treats IF and ELSE as blocks, and therefore generates this error?

If so, I understand the reason, but the message is not clear.

You must refactor your template.

See this issue: https://github.com/phalcon/cphalcon/issues/329

In short, {% block bockName %} cannot be embedded into other blocks, or into {% if %} branches.



4.2k
Accepted
answer
edited Jan '19

@lajosbencz, I don't agree with this error, and I don't think it makes sense, but as I said in the previous comment...

Hello @lajosbencz,

Thanks for your reply, but I still have not understood the reason for this error. Is it because the Volt treats IF and ELSE as blocks, and therefore generates this error?

If so, I understand the reason, but the message is not clear.

... I believe this message should be clearer.

I watched the Github thread and I notice that the Phalcon team is handling this error with low priority. So in this case, I had to do a dirty job so that I could solve my problem:

{# LOCKED MODE #}
<?php if (false === empty($this->session->get('locked_mode, true))) { ?>
    {{ partial('locked_mode_view') }}
{# UNLOCKED MODE #}
<?php } else { ?>
<div class="row">
    {{ partial('unlocked_mode_view') }}

    {% block content %}
        {{ partial('unlocked_mode_content') }}
    {% endblock %}
</div>
<?php } ?>

Amazingly, that way worked correctly... =[

In short, {% block bockName %} cannot be embedded into other blocks, or into {% if %} branches.

Nice hack! (no sarcasm, really!)