---
title: "Groovy templates"
canonical: "https://support.appfire.com/space/JMWE/461930609/Groovy%20templates"
format: markdown
---
> Macro (aura-html)

Groovy Template is a templating engine for JavaScript. It lets you insert dynamic content into any text through the use of templates. <span style="color: #000000">A template contains variables and/or expressions, which get replaced with values when a template is </span>*<span style="color: #000000">rendered</span>*<span style="color: #000000">.</span> This is very similar to JSP markup. 

**On this page:**


#### **Groovy templates in JMWE **

Groovy templates in JMWE are used in:

- [Comment issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/462094989) and [Comment related issues](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78056486) post-function to create the body of the comment by selecting `Groovy template` as the `Comment type`
- [Create/Clone issue(s)](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461472239) post-function to:
  - Set fields of the new issue by selecting `Groovy template` as the `Value type`
  - Add a comment to the current issue by selecting `Groovy template` as the `Comment type`
- [Set field value](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461767530) and [Set field value of related issues](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/78056381) post-functions to set a field value by selecting `Groovy template` as the `Value type`
- [Email issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461767713) post-function to write the `Subject, HTML body and Text body`
- [Link issues to the current issue](https://appfire.atlassian.net/wiki/spaces/JMWE/pages/461538264) post-function to write the `JQL search expression`

#### **Groovy templating features**

To output the result of a simple Groovy expression, write your Groovy code as `<%= some Groovy code %>. `For example:

```groovy
<%= issue.getKey() %>
```

For single-statement expressions, you can also use the following shortcut:

```
${issue.getKey()}
```

  
To simply execute a Groovy code and not output the result, write your Groovy code as `<% some Groovy code %`>. For example:

```groovy
<% log.debug("I was here") %>
```

You can also output the value of a variable or its properties using `$variable` or` $variable.someProperty`. For example:

`$currentUser` returns an ApplicationUser

`$currentUser.name` returns the username of the current user

To call a method on the variable, use `${variable.method()}`:

`${currentUser.getName()}` also returns the username of the current user

#### **Groovy template examples**

Write the issue key as a comment to the issue:

```groovy
Issue key: ${issue.get("issuekey")}
```

Comment an issue based on the priority of the issue:

```groovy
<% if (issue.get("priority").name == "Critical") { %>
The priority of the issue is <%=issue.get("priority").name %>. So Look out!
<% } %>
```

To send an Email to the Voters and Watchers of the issue when the issue is resolved, write this as the Subject of the Email (note that we mixed `<%= %>` and `${}` expressions only to show how both are valid):

```groovy
Hi All,
<% if (issue.assignee)
{%>
The issue <%= issue.key%> has been resolved by <%=issue.assignee.displayName%>
<%}
else
{%>
The issue ${issue.key} has been resolved
<%}%>
Regards,
<%=issue.get("project")?.getLead()?.getDisplayName()%>
```

:info: Note that you can also "print" to the text: If you would like to print the components of the project:

```
<% issue.getAvailableOptions("components").each() {
  print "Component: "+ it.name + "\n"
}
%>
```