PDS
PDS

Reputation: 582

Velocity template and java code inside

it's possible to use java code in velocity template ? for example use this int template:

double x = minutes/60 + (((minutes % 60)<=15)?0.0:((minutes % 60)<=45)?0.5:1.0);

Upvotes: 4

Views: 2789

Answers (1)

Sergiu Dumitriu
Sergiu Dumitriu

Reputation: 11601

No, Velocity is just a simple templating engine which prints anything that's not valid Velocity syntax.

But it does support computations, although with a much a simpler set of operations. This works in Velocity:

#set ($x = $minutes / 60)
#if ($minutes % 60 <= 15)
  #set ($x = $x + 0.0)
#elseif ($minutes % 60 <= 45)
  #set ($x = $x + 0.5)
#else
  #set ($x = $x + 1.0)
#end

Upvotes: 3

Related Questions