Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:34:36+00:00 2026-05-26T17:34:36+00:00

I am passing a list to a view. My array looks like this: [football,

  • 0

I am passing a list to a view. My array looks like this: [football, basketball, soccer]. In my view, I would like to display something like this:

1. football
2. basketball
3. soccer

This means that I would have to iterate through the list that is passed to the array, do a for loop on the elements. How would I do this in the template file?

For each element, I would have to get its index and add 1 to it. Now, I have no idea how to do this in the views. One way I thought about doing this would be to make a dictionary, like so, {'1', 'football': '2', 'basketball': '3', 'soccer'}, but since I already have the data in a list format, I would rather not convert it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:34:37+00:00Added an answer on May 26, 2026 at 5:34 pm

    You want the forloop.counter template variable.

    The for loop sets a number of variables available within the loop:

    forloop.counter The current iteration of the loop (1-indexed)

    So your code would look like:

    {% for sport in sports %}
        <p>{{forloop.counter}}. {{ sport }}</p>
    {% endfor %}
    

    Of course, for simply displaying the data as you do in your question, the easier way is just to show the items in an ordered list, and the browser will do the numbering for you:

    <ol>
    {% for sport in sports %}
        <li>{{ sport }}</li>
    {% endfor %}
    </ol>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using a BaseAdapter and passing to it a List of objects that have
I have a view spec that was passing but is broken now that pagination
I got a view List.aspx that is bound to the class Kindergarten In the
I have an Action which returns a partial view, and I would like to
In list view the position of particular row can easily be determined through array
I am passing a generic list of objects from a view page to an
In Edit view: I am passing ViewBag list for the ddl Controller: ViewBag.CountryList =
I'm creating a ListView that contains two TextViews and an ImageView. I'm passing data
I am passing a list to my scala page and I have a form
I am passing a generic list to a function , i want to enumerate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.