Login

Template filter to get a list element by its index

Author:
abidibo
Posted:
May 3, 2012
Language:
Python
Version:
1.4
Tags:
filter template-filter list get_at_index
Score:
0 (after 0 ratings)

Gets the list element at the given index

Example

{% for item1 in list1 %}
  <p>List1 element: {{ item1 }}</p>
  <p>List2 element: {{ list2|get_at_index:forloop.counter0 }}
{% endfor %}
1
2
3
4
5
6
7
from django import template

register = template.Library()

@register.filter
def get_at_index(list, index):
    return list[index]

More like this

  1. Template filter that divides a list into exact columns by davmuz 3 years, 5 months ago
  2. Template tag to sort a list of links by pytechd 7 years, 10 months ago
  3. Tags & filters for rendering search results by exogen 7 years, 3 months ago
  4. Recurse template tag for Django by Zarin 7 years, 5 months ago
  5. filter for extracting a number of paragraphs from any HTML code by rafadev 4 years ago

Comments

Please login first before commenting.