playframework - How to change active buttons in a dynamically generated bootstrap pagination? -


i have quiz system, can ask questions on different pages. page 1 shows picture of tree, page 2 of else... , user can write questions specific page.

now try implement simple pagination (i have seen example play-computer-base example, dont think need that), cant change pages.

this pagination far:

pagination

when user clicks on 2, should switch it.

therefore implemented navigation-element:

<nav>     <ul class="pagination">         @for(index <- 1 10){             <li class="@("active".when(index == currentpage))"><a href="@routes.application.index()">@index <span class="sr-only">(current)</span></a></li>         }     </ul> </nav> 

the problem within "active".when(index == currentpage) part, not correct @ moment. scala template, there way change active state of current button?

just try if condition currentpage inside for loop. should work.

<nav>     <ul class="pagination">         @for(page <- 1 10){             <!-- assuming know value of variable currentpage -->             @if(page == currentpage) {                 <!-- current page -->                 <li class="active"><a href="#">@{page}<span class="sr-only">(current)</span></a></li>             } else {                 <!-- anchor tag page -->                 <li><a href="route_to_that_page_number">@{page}</a></li>             }         }     </ul> </nav> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -