Skip to content

Parse error for start tags in conditional #19

@thibaudcolas

Description

@thibaudcolas

Given the following Django template,

{% if has_sidebar %}
<div class="col10">
{% else %}
<div class="col12">
{% endif %}
    <p>Main content</p>
</div>

{% if has_sidebar %}
<div class="col2">
    <p>Sidebar</p>
</div>

Jinjalint will produce the following parse error:

3:3: Parse error: expected one of 'autoescape', 'block', 'blocktrans', 'comment', 'endif', 'filter', 'for', 'if', 'ifchanged', 'ifequal', 'ifnotequal', 'not an intermediate Jinja tag name', 'spaceless', 'verbatim', 'with' at 2:3

This is quite a common pattern in templates, that's not the most readable for a small example like this but is usually used to limit repetition. Refactoring this to a more straightforward <div class="{% if has_sidebar %}col10{% else %}col12{% endif %}"> is possible in simple cases, but it might not always be desirable. It would be nice if jinjalint was able to parse this, understanding the conditional and the fact that in practice there will always be one and only one opening div.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions