junstyle / vscode-django-support

django formatter, highlight...
https://marketplace.visualstudio.com/items?itemName=junstyle.vscode-django-support
Apache License 2.0
4 stars 0 forks source link

Conditionally rendered tags showing errors #5

Closed SteveGiralt closed 1 year ago

SteveGiralt commented 1 year ago

When conditionally rendering a tag in a loop, I get an error which breaks formatting on this template. It renders correctly, so the error must be with the extension.

Example Code: `{% for attachment in question.question_attachments %} {% if forloop.counter0|divisibleby:3 %}

{% endif %} {{ attachment.description }} {% if forloop.counter|divisibleby:3 or forloop.last %}
          {% endif %}
        {% endfor %}`

Error: ERROR: Expected element start. Unexpected closing "tr" tag. Seems like your DOM is out of control.

ScreenShot - Screenshot 2023-07-05 at 11 59 33 AM

junstyle commented 1 year ago

because the tag <tr> and </tr> in different condition block. so you should avoid this situation. make sure start tag and end tag in same block.

SteveGiralt commented 1 year ago

Thanks you for your prompt response! This package is a lifesaver! Unfortunately, in this case I can not include both tags in the same condition block. Is there a way to tell the formatter to ignore this so the rest of the file can be formatted?

junstyle commented 1 year ago

off course you can ignore that part.

When you are not happy with how Prettier formats a certain element or section in the code, you can tell it to leave it in peace:

{# prettier-ignore #}
<div class="weird-formatting" >This will not be re-formatted</div> 
<div class="weird-formatting" >But this will be</div> 

You can also tell Prettier to leave entire regions as they are:

{# prettier-ignore-start #}
 ... 
{# prettier-ignore-end #}
SteveGiralt commented 1 year ago

Thank you so much