Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculation in Play 2.0 Framework template engine

Does play 2.0 template engine support the simple calculation in the html page.

Let us say, I create a sum.scala.html page:

@(a:String, b: String)

<html>
<head></head>
<body>
  <h1> answer is getSum(@a,@b) </h1>
</body>
</html>

Is there any way that we could "getSum of a and b" via some function? or Does any play 2.0 expert know any good idea about calculation in play 2.0 template engine? Thanks

like image 891
Chan Avatar asked Dec 05 '22 17:12

Chan


2 Answers

Have you tried @(a.toInt + b.toInt)?

like image 193
incrop Avatar answered Dec 21 '22 04:12

incrop


You can just pass the value to template, can't you ?

@(a:String, b: String, c: String)

<h1> answer for @a + @b is @c </h1>

You can also call function from Yourcontroller in the template:

@Yourcontroller.getSum(a,b);

In /app/controllers/Yourcontroller.java ad the function (simplest sample):

public static Integer getSum(String a, String b){
    Integer c = Integer.valueOf(a) + Integer.valueOf(b);
    return c;
}
like image 36
biesior Avatar answered Dec 21 '22 03:12

biesior