I want to write Django conditionals for html attributes, like
<a {% if item.link %} href="{{ item.link }}", target="_blank", rel="noopener", aria-label="{{ item }}" {% endif %}>
--- Content ---
</a>
I am using pug/jade, so I can't put jade/pug syntax inside "Content" block, the compiler breaks. I would like to know if I can handle that in any way to no repeat the "Content" block.
I tried also, withouth success:
a({% if item.link %} href="{{ item.link }}", target="_blank", rel="noopener", aria-label="{{ item }}" {% endif %})
----Content---
I finally found a way to achieve this. Incredibly the solution is very simple and I felt a little dumb when I found it:
<a {% if item.link %} href="{{ item.link }}", target="_blank", rel="noopener", aria-label="{{ item }}" {% endif %}>
--- Content ---
</a>
Just need to put the --- Content --- block in the same indentation level as the plain html content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With