Why can't I nest a block tag inside an if tag?

前端 未结 2 955
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 07:00

I have a master template file called base.html, in it I have the following code:

{% ifequal environment \"dev\" %}
    {% block stylesheets %}{%         


        
相关标签:
2条回答
  • 2020-12-19 07:05

    This question is no longer relevant - as of r12655 you can nest a block tag within a conditional.

    0 讨论(0)
  • 2020-12-19 07:10

    Edit (14th October, 2010):

    The original question title is no longer true, according to this comment on a ticket on Django.

    Original Answer:

    I'm not sure why not, but you could just do:

    {% block stylesheets %}
        {% ifequal environment "dev" %}
            ... something ....
        {% else %}
            {{ block.super }}
        {% endifequal %}
    {% endblock %}
    

    Having rethought this a bit - I guess that means repeating that logic inside each of your templates, which is fairly unsatisfactory, but I'll leave this answer here anyway. I've had a quick look through the Django tickets and can't find anything relevant.

    0 讨论(0)
提交回复
热议问题