Expression
Simple way to output the value of a java variable.
Syntax
Expression sections can appear anywhere in text or hash sections.
[= java_variable_or_expression]
Essentially, instead of saying out.println(whatever)
,
one can say [= whatever]
. (both are exactly equivalent).
Tag-Escape
To prevent the tag from being recognized, this tag can be escaped by
prefixing the start tag with a backslash: \[=
If an expression contains a java array, such as:
[=
x[i]], the ending ] of the array is seen as the end of the expression itself. The solution is to say: [= x[i\]]
instead.
Example
A simple molly page containing a simple expression.
[= 2+2 ]
4
Example
Expressions can contain either valid java expressions or previously
defined page variables.
[[
int feel = 0;
String greeting = "Hello World";
]]
[= greeting ]..
[= ((feel == 0) ?
"I feel good today" :
"I need a change")
]
Hello World..I feel good today
Example
An expression is convenient when writing an attribute value.
[[
String color = "#ccc";
]]