Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Playframework 2.0.x support <else if> in templates

I wonder if play 2.0.3 and higher supports else if in views? I only read that one have to code that way: if {...}else{if{...}else{...}} cannot believe that.

like image 973
Sven Malvik Avatar asked Dec 28 '12 19:12

Sven Malvik


People also ask

Which technique enables a fast coding workflow minimizes the number of characters and keystrokes required in a file?

Razor minimizes the number of characters and keystrokes required when writing a view template, and enables a fast, fluid coding workflow.

Which component is responsible for building play framework?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.

What is Scala HTML?

A Play Scala template is a simple text file that contains small blocks of Scala code. Templates can generate any text-based format, such as HTML, XML or CSV. The template system has been designed to feel comfortable to those used to working with HTML, allowing front-end developers to easily work with the templates.


2 Answers

I used an @ before the second if :

@if (true) { ... } else { @if (true) { ... } else { ... }} 
like image 167
Mar Cnu Avatar answered Oct 08 '22 04:10

Mar Cnu


The @Todd Flanders answer is right. In a wrapper @{}, you can write your normal Scala code. Example

@{   if (profile.sex == 0) {     <p class="col-md-6">Other</p>   } else if (profile.sex == 1) {     <p class="col-md-6">Male</p>   } else {     <p class="col-md-6">Female</p>   } } 
like image 41
Xuân-Lợi Vũ Avatar answered Oct 08 '22 04:10

Xuân-Lợi Vũ