Google Groups Home
Help | Sign in
ifequal not working?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Eloff  
View profile
 More options Jul 28 2007, 2:42 am
From: Eloff <dan.el...@gmail.com>
Date: Sat, 28 Jul 2007 06:42:43 -0000
Local: Sat, Jul 28 2007 2:42 am
Subject: ifequal not working?
Thinking myself clever I added enumerate as a filter and did:

{% for i, item in menu_items|enumerate %}
{% ifequal i|add:1 menu_items:length %} class="last-item"{% endifequal
%}

To me I expect it to be true only for the last item, I printed {i|add:
1} and it works as expected. However, what happens is it's always
true. I don't understand it, does someone know why this is?

Thanks,
-Dan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Ostgard  
View profile
 More options Jul 28 2007, 3:53 am
From: Nathan Ostgard <bula...@gmail.com>
Date: Sat, 28 Jul 2007 07:53:06 -0000
Local: Sat, Jul 28 2007 3:53 am
Subject: Re: ifequal not working?
ifequal can't do filters, unfortunately.

But you can do this:

{% for item in menu_items %}
  {% if forloop.last%} class="last-item"{% endif %}
{% endfor %}

Or

class="{{ forloop.first|yesno:"first," }} {{ forloop.last|
yesno:"last," }}"

On Jul 27, 11:42 pm, Eloff <dan.el...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Matthias Aust  
View profile
 More options Jul 28 2007, 3:55 am
From: "Stefan Matthias Aust" <eib...@googlemail.com>
Date: Sat, 28 Jul 2007 09:55:22 +0200
Local: Sat, Jul 28 2007 3:55 am
Subject: Re: ifequal not working?
2007/7/28, Eloff <dan.el...@gmail.com>:

> Thinking myself clever I added enumerate as a filter and did:

> {% for i, item in menu_items|enumerate %}
> {% ifequal i|add:1 menu_items:length %} class="last-item"{% endifequal
> %}

Dan, ifequal cannot evaluate its arguments. They must be variables,
numbers or constants in quotes. To special case the last element of a
list, do this:

 {% for item in items %}
   {% if forloop.last %} class="last" {% endif %}
   ...
 {% endfor %}

--
Stefan Matthias Aust


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eloff  
View profile
 More options Jul 28 2007, 10:44 am
From: Eloff <dan.el...@gmail.com>
Date: Sat, 28 Jul 2007 14:44:26 -0000
Local: Sat, Jul 28 2007 10:44 am
Subject: Re: ifequal not working?

> Dan, ifequal cannot evaluate its arguments. They must be variables,
> numbers or constants in quotes.

Thanks Stefan, I'll remember that in future.

> But you can do this:

> {% for item in menu_items %}
>   {% if forloop.last%} class="last-item"{% endif %}
> {% endfor %}

Thanks Nathan, that's very helpful, much neater too. Figures there'd
be a way to do that in Django.

-Dan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google