Is there a way to define custom templates with optional parameters?
Something like
%{
try {
_name = _name
} catch (Exception e) {
_name = "Guest"
}
}%
Hello ${_name}
This way if the template is called with name: "Foo", then it is used, if not, “Guest” is used.
I tried the above, and besides having the problem of not being reusable on the same page, I couldn’t get it to work at all (template crashed or didn’t compile, the catch clause did not run).
Is there a better way?
P.S. I’m using Play 1.2.4+ (latest 1.2 branch)
you can use groovy expressions like this
or you can do it the hard way using java code.
http://www.playframework.org/documentation/1.2.4/templates#fasttags