1

If I pass a boolean value to the view, for example "checked", how to show the different html elements according to the checked value(that is , true or false) ?

#{if ${checked}}
     <p>aaa</p>
#{/if}
#{else}
     <p>bbb</p>
#{/else}

I try the above code but failed...

2 Answers 2

4
#{if checked}
     <p>aaa</p>
#{/if}
#{else}
     <p>bbb</p>
#{/else}

The ${} syntax, is only for printing values into your template. Inside the #{if } tag, playframework expects groovy syntax.

Also, check out the documentation for the #{if} tag.

0
3

In addition to @aaberg response with an inline if :

<input type="checkbox" ${checked ? 'checked="checked"' : ''} />
<span>The previous checkbox is ${checked ? "checked" : "not checked"} !</span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.