Skip to content

[VOLT] Support for embedding blocks into other blocks #17145

Description

@applejohnny

With inheritance of multiple files like a.volt extends b.volt extends c.volt, I have to use embedding blocks. Otherwise there's no profit to use inheritance more than one nesting level.

Activity

  1. xpundel commented on Mar 3, 2013

    @xpundel

    The same question. Is there a plans to implement this feature?

  2. xpundel commented on Jul 4, 2013

    @xpundel

    Greetings!
    Is there any plans to implement this feature?

  3. breezewish commented on Aug 23, 2013

    @breezewish

    Hi, is there any plans? I think this feature is important.

  4. gianks commented on Aug 28, 2013

    @gianks

    +1

  5. gsouf commented on Sep 2, 2013

    @gsouf

    I upvote for the feature

  6. Raistlfiren commented on Oct 14, 2013

    @Raistlfiren

    Agreed. It would be nice to have a block inside an if statement.

  7. kvokov commented on Oct 30, 2013

    @kvokov

    I think it's very useful feature. Waiting for this!

  8. gsouf commented on Oct 30, 2013

    @gsouf

    Actually this is why i'm using twig instead of volt

  9. raisoblast commented on Nov 14, 2013

    @raisoblast

    +1 for this great feature

  10. vladimmi commented on Jan 14, 2014

    @vladimmi

    Any improvements after almost a year? As for me, this is the most needed missing feature in Volt

  11. redstrike commented on Jul 19, 2014

    @redstrike

    At this moment, Phalcon 2 is missing some features from 1.x and still not stable enough for using in production. Why don't you fix this bug in Phalcon 1.3.3?

  12. immortalx commented on Sep 4, 2014

    @immortalx

    +1 to implement this feature in 1.3.x

  13. vladimmi commented on Sep 4, 2014

    @vladimmi

    It seems, developers are focused only on 2.x branch and will not implement any new features in 1.3. Anyway, this wasn't implemented for 1.5 years so... You can use Twig if you need this feature.

  14. gsouf commented on Sep 4, 2014

    @gsouf

    @phalcon told

    This will be implemented in Phalcon 2 with Zephir

  15. 67 remaining items

  16. transferred this issue fromphalcon/phalconon Jan 23, 2026
  17. self-assigned this
    on Jun 13, 2026
  18. added
    new feature request
    5.0
    on Jun 13, 2026
  19. transferred this issue fromphalcon/volton Jun 13, 2026
  20. added theissue type on Jun 13, 2026
  21. moved this from Backlog to Active Sprint in Phalcon v5on Jun 13, 2026
  22. added and removed
    5.0
    on Jun 13, 2026
  23. added this to Phalcon v7 and removed this from Phalcon v5on Jun 13, 2026
  24. Izopi4a commented on Oct 16, 2026

    @Izopi4a
    Member

    A proposal for this one, for v7: #NFR-07 (resolve inheritance on the AST).

    With inheritance resolved on the AST before compiling, nested blocks need no new syntax. Blocks are collected by name at any depth, and every block node is replaced by its most derived definition. The parser side is a 12-line change in base.c: it stops refusing a block while block_level > 0. That check is also what makes a block inside {% if %} fail today, since if/for/switch bump the same counter. Patch: https://github.com/Izopi4a/cphalcon/blob/nfr-volt/resources/rfc/volt/prototype/patches/01-nested-blocks.patch

    Prototyped on master (5.23.0), with the original case from this issue:

    {# base.volt #}
    <html><body>{% block body %}{% endblock %}</body></html>
    
    {# section.volt #}
    {% extends "base.volt" %}
    {% block body %}
    <main>{% block content %}{% endblock %}</main>
    <aside>{% block sidebar %}<h3>Help</h3>{% endblock %}</aside>
    {% endblock %}
    
    {# leaf.volt #}
    {% extends "section.volt" %}
    {% block content %}Article{% endblock %}
    {% block sidebar %}{{ super() }}<p>Related</p>{% endblock %}
    today:    Phalcon\Mvc\View\Exception: Embedding blocks into other blocks is not supported in section.volt on line 3
    proposed: <html><body>
              <main>Article</main>
              <aside><h3>Help</h3><p>Related</p></aside>
              </body></html>
    
    • Overriding only the inner block, only the outer one, or neither works, and super() works at every level.
    • Blocks inside if/for work as in Twig: the block is always defined, and the condition decides where it renders.
    • A block name defined twice in one template becomes an error. Today the last one wins silently.

    Examples E1/E2 with captured output: https://github.com/Izopi4a/cphalcon/blob/nfr-volt/resources/rfc/volt/examples.md. The tests are in https://github.com/Izopi4a/cphalcon/blob/nfr-volt/resources/rfc/volt/prototype/tests/Prototype/InheritanceTest.php, next to the same templates failing on the stock build in tests/Today/InheritanceTodayTest.php.

    this needs to be approved first #17679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0new feature request

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions