Support and use parameters in a template file
Procedure
-
Create a template file, for example,
mycompany.templates.NotifyAdminTemplate.gst. -
At the top of the template file, create a parameter
definition.
For example, the following argument list includes a
Stringargument and abooleanargument:<%@ params(personName : String, contactHR: boolean) %> -
Later in the template, use template tags that use the
values of those parameters.
For example:
The person ${ personName } must update their contact information in the company directory. <% if (contactHR) { %> Call the human resources department immediately. <% } %> - If Studio is running a server, you must load the changed file by remaking the project. From the menu, click .
-
To run the template, add your parameters to the call
to the renderToString method or after the writer parameter to
the render method.
For example, in the Gosu Scratchpad:
print(mycompany.templates.NotifyAdminTemplate.renderToString("Pamela Castillo", true))
