JMWE for Jira Cloud provides support for shared Nunjucks templates. This is very useful to share macros across post-functions, as well as to split lengthy templates when you run into this issue: MWEC-159.
This page explains how to create shared Nunjucks templates and reuse them from other Nunjucks templates written in JMWE post-functions or the Nunjucks scripts tester.
On this page: |
Name
.Description
.Add
. The Nunjucks template editor is displayed.Save
.Edit
for the template you wish to modify.Save
to save your changes.Delete
for the template you wish to delete.You can import or include a shared Nunjucks template into your post-functions or Script tester using the respective tags available in Nunjucks.
Nunjucks macros have two limitations that you need to be aware of:
|
Example 1: To set the Priority of the issue based on its impact.
Mappings
.Provide the following template in the Nunjucks editor.
{% macro priorityFromImpact(impact) %} {%- if impact == "Company wide" %} Highest {% elseif impact == "More than one project" %} High {% elseif impact == "Single project" or impact == "Individual" %} Medium {% else %} Low {% endif %} {% endmacro -%} |
Write the following template in the editor.
{% import "Mappings" as Mappings %} {{Mappings.priorityFromImpact(issue.fields.Impact)}} |
Example 2: To provide a resolution date excluding the weekends and based on the priority of the issue:
addDateExcludingWeekends
.Provide the following template in the Nunjucks editor.
{% set priority = issue.fields.priortiy.name %} {% if priority == "Highest" %} {% set nod = 2%} {% elseif priority == "High"%} {% set nod = 4%} {% elseif priority == "Medium"%} {% set nod = 6%} {% elseif priority == "Low"%} {% set nod = 8%} {% else %} {% set nod = 6%} {% endif %} {{ from | date('businessAdd', nod ) | date() }} |
Write the following template in the editor.
Hi {{issue.fields.reporter.displayName }}, This is in response to the ticket : {{issue.key}} that you created with us on {{issue.fields.created | date("DD/MM/YYYY") }}. Your issue will be resolved on or before :{% set from = issue.fields.created %} {% include "addDateExcludingWeekends" %} Regards, {{ issue | projectInfo | field("lead.displayName")}} |
Example 3: To include a shared email body template in an Email Issue post-function:
emailHtmlBody
In the HTML Body field of the Email Issue post-function, write the following template:
{% include "emailHtmlBody" %} |