Reputation: 3219
Can't seem to get a variable percentage width output in my Django tag.
{% with "width: "|add:percent|add:"%" as percent_style %}
<div class="percentile" style={% include percent_style %} />
{% endwith %}
What am i doing wrong here? I get this error
django.template.exceptions.TemplateDoesNotExist: %
Upvotes: 3
Views: 3604
Reputation: 8525
It seems to be easy to do, instead of trying to include
, just use the variable concatenated with the percent %
sign. You don't need to use {% with %} {% endwith %}
<div class="percentile" style="width:{{ percent }}%" />
Upvotes: 2
Reputation: 47354
Instead of include
tag which trying to find template named percent_style
you should simple use {{ percent_style }}
:
{% with "width: "|add:percent|add:"%" as percent_style %}
<div class="percentile" style="{{ percent_style }}" />
{% endwith %}
Upvotes: 2