Background Colors / Fill Settings

Table of contents:

  1. General Syntax
  2. Dynamically setting Background Color
  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 color using 3 methods:

  1. 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>>
    Output:


  2. A string containing an HTML color code:
    <<backColor [“#F08080”]>>text with light coral background<</backColor>>
    Output:


  3. An integer value defining RGB (red, green, blue) components:
     <<backColor [0xFFFF00]>>text with yellow background<</backColor>>
    Output:

Dynamically setting Background Color

You can pass the required color to be populated in the template in the input JSON. Make sure to include quotes if the color is a string (KnownColor enumeration or HTML color code) and no quotes if the color 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 color 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