I know there is the possibility to define a method in templates like this:
@def myMethod(String parameter){
before @parameter after
}
and use it:
@myMethod("my object")
This will output:
before my object after
Can I define the myMethod
in Java code and use it in multiple templates ?
You don't need to define that method in Java code. Instead in your rythm template home directory create a file named
__global.rythm
, and define that method there, then all your rythm template will automatically pick up that method because__global.rythm
will be@include
by Rythm engine in every template automatically. Below is a real global rythm file from my project: