panchicore
panchicore

Reputation: 11932

what happen with this django-template if tag?

Sorry if I am being a moron, but what happen with this if tag ?

view return:

return render_to_response('productos/por_estado.html', {'productos':productos}, 
                   context_instance=RequestContext(request))
#Im not returning 'estado' !

template:

{% if estado %}
{% block activos_active %}class="active"{% endblock %}
{% endif %}

template html result:

class="active"

:S

Upvotes: 0

Views: 181

Answers (2)

vikingosegundo
vikingosegundo

Reputation: 52237

One way to set class="active" could be just this

<div{% if estado %} class="active"{% endif %}>....</div>

Upvotes: 1

Ryan Duffield
Ryan Duffield

Reputation: 19029

Block tags cannot be set conditionally, arguably because they are part of template inheritance. I believe this was an explicit design decision by the Django developers. See this Django ticket as well as this other question on Stack Overflow.

Upvotes: 4

Related Questions