Skip to content

[DX] Throw exception when using conditionals outside of blocks in a template extending another #1639

Description

@SpacePossum

When using a setup like:

{# main.twig #}
{% set test = false %}

<h1>Hello</h1>

{% block dialog %}
    dialog base
{% endblock %}
{# test.twig #}

{% extends 'main.twig' %}

{% if false and test %}

    {% block dialog %}

        dialog override

        {% if test == true %}
            test is true
        {% else %}
            test is false
        {% endif %}

    {% endblock %}

{% endif %}

The output is:

<h1>Hello</h1>

    dialog override

        test is false

This is confusing. When printing anything in the extending template outside of the block a syntax exception is thrown like: A template that extends another one cannot have a body in "test.twig" at line 19.. I think an exception should be thrown as well when using conditionals outside of blocks.
Fiddle @ http://twigfiddle.com/818v58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions