[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to access an element in a list using forloop.counter in django templates?


I have a list in template.
I need to access that list based on a forloop.counter.

For example :

if forloop.counter is 1 then i need to access list[1]
if forloop.counter is 5 then i need to access list[5]
.
so on..........

I tried below techniques to solve the above problem.but none of them
is working.
Any hint on how to do this?

1. {%  for  k in klist  %}

                {{ mylist.forloop.counter }}  #This code is not
working
    {% endfor %}


2.  {%  for  k in klist  %}

           {{% with forloop.counter as xl %}
                {{mylist.x }} #This code is not working
          {% endwith %}

   { %endfor %}

3.  {%  for  k in klist  %}
             {{  mylist|slice:forloop.counter:forloop.counter }} #This
code is not working
   { %endfor %}

Regards
Rama vadakattu










--~--~---------~--~----~------------~-------~--~----~
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@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to django-users+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---



This mailing list archive is a service of Copilotco.