Background Colours / Fill Settings

Table of contents:

  1. General Syntax
  2. Dynamically setting Background Colour
  3. Conditional Background Colour

General Syntax

You can set the background colour or fill colour of a table dynamically within the template using a backColor tag. Note, the backColor tag can be used anywhere in the template document except charts.

The basic template syntax is as follows:

<<backColor [color]>>text with color background<</backColor>>

You can define the colour using a string containing the case-insensitive name of a member of the KnownColor enumeration. Please see a list here: Microsoft Learn - KnownColor Enumeration

<<backColor [“red”]>>text with red background<</backColor>>

Dynamically setting Background Colour

You can pass the required colour to be populated in the template in the input JSON. Make sure to include quotes if the colour is a string (KnownColor enumeration or HTML color code) and no quotes if the colour is an integer (RGB value).

Example JSON:

{
"items": [
{
"Name": "Red",
"Color": "Red"
},
{
"Name": "Green",
"Color": "Green"
},
{
"Name": "Blue",
"Color": "Blue"
}
]
}

Template syntax:

<<foreach [item in items]>><<backColor [item.Color]>><<[item.Name]>><</backColor>>
<</foreach -greedy>>

 

Conditional Background Colour

You can add Conditional Expressions to your template to set the background colour based on the values being populated.

Example JSON:

{
"requests": [
{
"CompanyName": "Encodian",
"Approval": "Approved"
},
{
"CompanyName": "Microsoft",
"Approval": "Pending"
},
{
"CompanyName": "Encodian",
"Approval": "Failed"
}
]
}

Template syntax:

Column 1: <<foreach [varReq in requests]>><<[varReq.CompanyName]>>
Column 2: <<if [varReq.Approval == “Approved”]>><<backColor [“Lime”]>><<[varReq.Approval]>><</backColor>><<elseif [varReq.Approval == “Pending”]>><<backColor [“Cyan”]>><<[varReq.Approval]>><</backColor>><<else>><<backColor [“IndianRed”]>><<[varReq.Approval]>><</backColor>><</if>><</foreach>>

Template:

Output:

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk