playframework 2.0 - HTML attribute in Scala Template -


i java developer started learn play framework. have been trying below template working cant seem it. have got following in scala template

@navitem(label: string, link1: string) = {     @{if (application.isauthenticated()) {     <li class="active">         <a href="@link1">label</a>     </li>     }     else {     <li class="disabled">         <a href="@link1">{label}</a>     </li>     }     } } 

i calling later in template so

<ul class="nav"> @navitem("search documents", "/search") </ul> 

the generated link has href localhost:9000/@link1 instead of localhost:9000/search. not sure whats going on.

ps: if change template below works fine. want understand why above template wont work.

@navitem(label: string, link1: string) = {     <li class="@(if (application.isauthenticated()) "active" else "disabled")">         <a href="@link">@label</a>     </li> } 

not quite sure this, guess following: @{ ... } indicates beginning of dynamic statement , of content treated scala code. thus, normal if-condition 2 strings result, both of returned in template.

why marking multi-line code block anyway? have tried this? (note missing curly braces after 2nd @ sign):

@navitem(label: string, link1: string) = {   @if(application.isauthenticated()) {     <li class="active">       <a href="@link1">@label</a>     </li>   } else {     <li class="disabled">       <a href="@link1">@label</a>     </li>   } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -