Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Excerpt

Tags are special blocks that perform operations on sections of the template and Expressions are literal expressions similar to those in javascript.

...

iterates over the comments variable and displays each comment body.

include

The include tag pulls in other templates in place. It's useful when you need to share smaller chunks across several templates. An included template does not participate in the block structure of its including template; it has a totally separate inheritance tree and block namespace. In other words, an include is not a pre-processor that pulls the included template code into the including template before rendering; instead, it fires off a separate render of the included template, and the results of that render are included.

Syntax:

Code Block
{% include "Test" %}

where Test is the name of the shared Nunjucks template saved in the Admin page.

import

The import tag loads a template and allows you to access its exported values. Macros and top-level assignments are exported from templates, allowing you to access them in your current template.

Syntax:

Code Block
{% import "Test" as Test1 %}
{{Test1.sum(2,3)}} {# Calling the macro sum #}

...

Shared Nunjucks template:

Name of the template : Set Priority Mappings

Code Block
{% macro setPrioritypriorityFromImpact(impact) %} 
	{{Low}}
    {%- if impact == "Company wide" %}
        {{"Highest"}}
    {% endif %}
    {%- if elseif impact == "More than one project" %}
        {{"High"}}
    {% endif %}
    {%- if elseif impact == "Single project" or impact == "Individual" %}
        {{"Medium"}}Medium
    {% else %}
    	Low
    {% endif %}
{% endmacro -%}

Access the template in a post-function to set the Priority of the issue:

Code Block
{% import "Set PriorityMappings" as SPMappings %}
{{SPMappings.setPrioritypriorityFromImpact(issue.fields[".Impact"])}}

Whitespace control

The Nunjucks script outputs everything outside of variable and tag blocks verbatim, with all the whitespace (spaces, tabs, newlines,...) as it is in the script. For example, the following script:

Code Block
linenumberstrue
This issue is
{% if issue.fields.priority.name == "Blocker" %}
  urgent
{% else %}
  not urgent
{% endif %}

will result in the following output:

Code Block
linenumberstrue
This issue is
  not urgent

If you don't want the extra whitespace between Nunjucks tags, then you can add the minus sign (-) to the start or end block to strip leading or trailing whitespace. For example:

...

See the Nunjucks documentation for more details.

Info

We already automatically remove spaces and carriage returns surrounding template result values in most post-functions.

Expressions

Mathematical expressions

...