List Info

Thread: Using forloop.counter0 on a variable




Using forloop.counter0 on a variable
user name
2007-12-17 12:06:29
Hello,
I have the following in my template:

{% for a in thespinfo %}
{{ secondprice.forloop.counter0|floatformat:2 }}
{% endfor %}

However, nothing appears when I run this code

///////////////

My secondprice variable contians a list like ['25', '14',
'56'].  Each
time that my for loop is run through then I want to display
that
current element in the secondprice element.  So the first
time my loop
is run through then I want it to loop like:

{{ secondprice.0|floatformat:2 }}...then next time like {{
secondprice.
1|floatformat:2 }}...etc



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


Re: Using forloop.counter0 on a variable
user name
2007-12-17 13:54:20
You can do that with a very simple template tag

register = template.Library()

register.simple_tag
def get_element(list, index):
    # You should catch IndexError here.
    return list[index]


Template side:

{% get_element secondprice forloop.counter0 %}


Regards,
Martin Conte Mac Donell
 

On Dec 17, 2007 3:06 PM, Greg < gms3651hotmail.com" target="_blank"> gms3651hotmail.com> wrote:

Hello,
I have the following in my template:

{% for a in thespinfo %}
{{ secondprice.forloop.counter0|floatformat:2 }}
{% endfor %}

However, nothing appears when I run this code

///////////////

My secondprice variable contians a list like ['25&#39;, '149;, '569;].  Each
time that my for loop is run through then I want to display that
current element in the secondprice element.  So the first time my loop
is run through then I want it to loop like:

{{ secondprice.0|floatformat:2 }}...then next time like {{ secondprice.
1|floatformat:2 }}...etc









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

Re: Using forloop.counter0 on a variable
user name
2007-12-17 15:53:02
Martin,
Yep...that worked.  Thanks!

However, now I'm not using the '|floatformat:2'.  Is there
anyway that
I can use that in my template with the new way:

<td height="10">${% get_element secondprice
forloop.counter0 %}</td>

For an example...currently I'm getting back 124.1...I would
like to
have it be 124.10


On Dec 17, 1:54 pm, "Martin Conte Mac Donell"
<refl...gmail.com>
wrote:
> You can do that with a very simple template tag
>
> register = template.Library()
>
> register.simple_tag
> def get_element(list, index):
>     # You should catch IndexError here.
>     return list[index]
>
> Template side:
>
> {% get_element secondprice forloop.counter0 %}
>
> Regards,
> Martin Conte Mac Donell
>
>
>
>
>
> > On Dec 17, 2007 3:06 PM, Greg < gms3...hotmail.com> wrote:
>
> > > Hello,
> > > I have the following in my template:
>
> > > {% for a in thespinfo %}
> > > {{ secondprice.forloop.counter0|floatformat:2
}}
> > > {% endfor %}
>
> > > However, nothing appears when I run this
code
>
> > > ///////////////
>
> > > My secondprice variable contians a list like
['25', '14', '56'].  Each
> > > time that my for loop is run through then I
want to display that
> > > current element in the secondprice element. 
So the first time my loop
> > > is run through then I want it to loop like:
>
> > > {{ secondprice.0|floatformat:2 }}...then next
time like {{ secondprice.
> > > 1|floatformat:2 }}...etc- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Using forloop.counter0 on a variable
user name
2007-12-17 17:58:27
What about

<;td height=&quot;10">$
 ; &nbsp; {% filter floatformat:2 %}
   &nbsp;  &nbsp; {% get_element secondprice forloop.counter0 %}
 &nbsp;  {% endfilter %}
</td>

Regards,
--
Martín Conte Mac Donell

On Dec 17, 2007 6:53 PM, Greg < gms3651hotmail.com">gms3651hotmail.com> wrote:

Martin,
Yep...that worked.  Thanks!

However, now I'm not using the '|floatformat:2&#39;.  Is there anyway that
I can use that in my template with the new way:

<td height=&quot;10">${% get_element secondprice forloop.counter0 %}</td&gt;

For an example...currently I'm getting back 124.1...I would like to
have it be 124.10


On Dec 17, 1:54 pm, "Martin Conte Mac Donell&quot; < refl...gmail.com"> refl...gmail.com>
wrote:
> You can do that with a very simple template tag
>
&gt; register = template.Library()
&gt;
> register.simple_tag
&gt; def get_element(list, index):
>     # You should catch IndexError here.
>     return list[index]
>
> Template side:
>
> {% get_element secondprice forloop.counter0 %}
>
&gt; Regards,
&gt; Martin Conte Mac Donell
&gt;
>
&gt;
>
>;
> > On Dec 17, 2007 3:06 PM, Greg < gms3...hotmail.com">gms3...hotmail.com> wrote:
>;
> > > Hello,
&gt; > > I have the following in my template:
>
> > > {% for a in thespinfo %}
> > > {{ secondprice.forloop.counter0|floatformat:2 }}
> > > {% endfor %}
>
&gt; > > However, nothing appears when I run this code
>;
> > > ///////////////
>
> > > My secondprice variable contians a list like ['25&#39;, '149;, '569;].  Each
> > > time that my for loop is run through then I want to display that
>; > > current element in the secondprice element.  So the first time my loop
> > > is run through then I want it to loop like:
>
> > > {{ secondprice.0|floatformat:2 }}...then next time like {{ secondprice.
> > > 1|floatformat:2 }}...etc- Hide quoted text -
>
>; - Show quoted text -




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

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )