Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error for start tags in conditional #19

Open
thibaudcolas opened this issue May 9, 2019 · 0 comments
Open

Parse error for start tags in conditional #19

thibaudcolas opened this issue May 9, 2019 · 0 comments

Comments

@thibaudcolas
Copy link

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.

@thibaudcolas thibaudcolas changed the title Parse error for start tags added in conditional Parse error for start tags in conditional May 9, 2019
thibaudcolas added a commit to thibaudcolas/wagtail that referenced this issue May 9, 2019
thibaudcolas added a commit to thibaudcolas/wagtail that referenced this issue May 9, 2019
thibaudcolas added a commit to thibaudcolas/wagtail that referenced this issue May 10, 2019
thibaudcolas added a commit to wagtail/wagtail that referenced this issue May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant