Support and use parameters in a template file

Procedure

  1. Create a template file, for example, mycompany.templates.NotifyAdminTemplate.gst.
  2. At the top of the template file, create a parameter definition.
    For example, the following argument list includes a String argument and a boolean argument:
    <%@ params(personName : String,
    contactHR: boolean) %>
  3. 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.
    <% } %>
  4. If Studio is running a server, you must load the changed file by remaking the project. From the menu, click Build > Make Project.
  5. 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))