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

  • SEARCH
  • Home
  • 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 9215529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:13:27+00:00 2026-06-18T02:13:27+00:00

In Play! 1, it was possible to get the current index inside a loop,

  • 0

In Play! 1, it was possible to get the current index inside a loop, with the following code:

#{list items:myItems, as: 'item'}
    <li>Item ${item_index} is ${item}</li>
#{/list}

Is there an equivalent in Play2, to do something like that?

@for(item <- myItems) {
    <li>Item ??? is @item</li>
}

Same question for the _isLast and _isFirst.

ps: this question is quite similar, but the solution implied to modify the code to return a Tuple (item, index) instead of just a list of item.

  • 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-06-18T02:13:28+00:00Added an answer on June 18, 2026 at 2:13 am

    Yes, zipWithIndex is built-in feature fortunately there’s more elegant way for using it:

    @for((item, index) <- myItems.zipWithIndex) {
        <li>Item @index is @item</li>
    }
    

    The index is 0-based, so if you want to start from 1 instead of 0 just add 1 to currently displayed index:

    <li>Item @{index+1} is @item</li>
    

    PS: Answering to your other question – no, there’s no implicit indexes, _isFirst, _isLast properties, anyway you can write simple Scala conditions inside the loop, basing on the values of the zipped index (Int) and size of the list (Int as well).

    @for((item, index) <- myItems.zipWithIndex) {
        <div style="margin-bottom:20px;">
            Item @{index+1} is @item <br>
                 @if(index == 0) { First element }
                 @if(index == myItems.size-1) { Last element }
                 @if(index % 2 == 0) { ODD } else { EVEN }
        </div>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Play 2.0.1 I defined the following route: GET /demo/list controllers.Demos.listDemos(page: Int ?= 0,
Is there any possible way to PLAY a you tube video on page load
Are there any existing examples of code where it is possible to do something
Whether is it possible to get default media player using Javascript, customize play controls
Is it possible (or is there a technique) to get an image.ondata event client
I have a question that, Is it possible to get and play the iPod
This is the simplest possible AVAudioPlayer code, and it's just failing to play anything
So, the flowplayer documentation says that there are two ways to get the current
In a play framework 1.2.4 Controller, is it possible to get the contents of
Is it possible work with subdomains in Play 2.0 conf/routes? Like Play 1.1: GET

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.