> On Mon, Apr 4, 2011 at 7:34 PM, Ethan Yandow <flibitb...@gmail.com> wrote:
>> Hey Mr. Django! I am trying to have different information display in
>> the same block depending on a variable "choice" which is simply an
>> int. The way I was planning on doing so was going to be something like
>> the bellow code:
>>
>> {% extends "index.html"%} {%block head%}
>>
>> Welcome to Piss && ink {{user}}
>>
>> {%endblock head%}
>> {%block one%}
>> The temperature in {{city}} is {{temperature}}&deg
>>
>> {%endblock one%} {%if choice1 == 2 %} {%block two%}
>> The temperature in {{city}} is {{temperature}}&deg
>>
>> {%endblock two%} {% endif %} {%comment%}{%if choice1 == 2 %} {%block
>> two%}
>> The temperature in {{city}} is {{temperature}}&deg
>>
>> {%endblock%} {% endif %}{%endcomment%} {%block two%} {%csrf_token%} {%
>> if new_event %}
>> {{new_event}}
>>
>> {% endif %} {%endblock%}
>> Now, the problem I am having is that the template doesn't like that
>> there are two blocks of the same name in the template. For some reason
>> it doesn't seem to care about the {%if%} statement that is checking
>> where the {%block%} is supposed to go. I thought that the {%if%}
>> statement would only execute what was inside itself depending on its
>> parameters but it doesn't seem to be doing that. It displays
>> everything inside the {%if%} no matter what "choice1" is equal too :
>> ( Does anyone have any idea how I might be able to fix this? Thanks

On Tue, Apr 5, 2011 at 11:00 AM, Calvin Spealman <ironfro...@gmail.com> wrote:
> Just put the condition inside the block.

By way of clarification -- there's a reason that you need to take this approach.

{% block %} tags are the one and only example of precedence rules in
Django's template language. Blocks are evaluated before every other
tag, because they involve the gross structure of the template itself.
You can't have a "conditional block", because the conditional tags
aren't evaluated until after the block is evaluated.

Yours
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to