Twig
Twig copied to clipboard
If statement with nothing set inside throws error
Create an "if" statement with nothing set inside throws error if this is done outside the {% block content %} tag.
{% extends "_layouts/_layout.twig" %}
{% if craft.app.request.segment(2) != "" %}
{% else %}
{% set foo = "bar" %}
{% endif %}
{% block content %}
{# IT DOESN'T MATTER WHAT'S IN HERE #}
{%endblock %}
or without the {% else %}
{% extends "_layouts/_layout.twig" %}
{% if craft.app.request.segment(2) != "" %}
{% endif %}
{% block content %}
{# IT DOESN'T MATTER WHAT'S IN HERE #}
{%endblock %}
Debugging this, it seems to be caused by the removal of whitespace-only text nodes that are at the root of child template. This breaks the structure of the IfNode tests.
We might want to replace them with an empty Node instead of removing them entirely.
Anyone willing to work on a fix?
I'm gonna give it a try.
I've taken over the PR where I took a different approach to fix the bug.