Re: Using the same block in a django template to display different information depending on a variable

2011-04-04 Thread Sam Walters
Hey

Block tags dont work like that.

{%if choice1 == 2 %}

{% include "sometemplate.html" %}

{%endif%}

instead of:

 {%if choice1 == 2 %} {%block two%}
> The temperature in {{city}} is {{temperature}}
>
> {%endblock two%} {% endif %}


I hope that was what you were thinking...
http://docs.djangoproject.com/en/1.3/topics/forms/

There is an example in the form docs.


cheers

sam_w

On Tue, Apr 5, 2011 at 9:34 AM, Ethan Yandow  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}}
>
> {%endblock one%} {%if choice1 == 2 %} {%block two%}
> The temperature in {{city}} is {{temperature}}
>
> {%endblock two%} {% endif %} {%comment%}{%if choice1 == 2 %} {%block
> two%}
> The temperature in {{city}} is {{temperature}}
>
> {%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
>
> --
> 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.
>
>

-- 
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.



Re: Using the same block in a django template to display different information depending on a variable

2011-04-04 Thread Russell Keith-Magee
> On Mon, Apr 4, 2011 at 7:34 PM, Ethan Yandow  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}}
>>
>> {%endblock one%} {%if choice1 == 2 %} {%block two%}
>> The temperature in {{city}} is {{temperature}}
>>
>> {%endblock two%} {% endif %} {%comment%}{%if choice1 == 2 %} {%block
>> two%}
>> The temperature in {{city}} is {{temperature}}
>>
>> {%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  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.



Re: Using the same block in a django template to display different information depending on a variable

2011-04-04 Thread Calvin Spealman
Just put the condition inside the block.

On Mon, Apr 4, 2011 at 7:34 PM, Ethan Yandow  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}}
>
> {%endblock one%} {%if choice1 == 2 %} {%block two%}
> The temperature in {{city}} is {{temperature}}
>
> {%endblock two%} {% endif %} {%comment%}{%if choice1 == 2 %} {%block
> two%}
> The temperature in {{city}} is {{temperature}}
>
> {%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
>
> --
> 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.
>
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

-- 
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.