AlxVallejo
AlxVallejo

Reputation: 3219

Django template variable in style tag

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

Answers (2)

Lemayzeur
Lemayzeur

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

neverwalkaloner
neverwalkaloner

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

Related Questions