Design

Colors

Applying dynamic colors to elements (text, row, cell, ...)
ENTERPRISE FEATURE Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
  v4.0+ 

:color(scope, type)

v4.17.0+

Apply the color on the text, paragraph, table row or table cell

Params Description Type
scope Specifies the element to be color-changed
- p : the current paragraph where the tag is (by default)
- cell : the current cell of a table
- row : the current row of a table
- shape : the current shape
- part : for text section (the color is applied within the same styled of the element)
String
type Sefines the property to be modified and supports - text for the text color (by default)
- highlight to highlight the text
- background for cells, rows and shapes
- border for shapes only
String

Important Notes:

Compatible with PDF, ODT, ODP, DOCX, HTML files.

Simple text color

The following example changes the text color to red:

data
{
  "flowerColor": "#FF0000"
}
template
Color of roses {d.flowerColor:color(p)}This paragraph is not colored.
Carbone Merge Icon
result
Color of roses This paragraph is not colored.

Condition and color

The following example changes the text color based on a condition.

Details:

data
{
  "test"      : "OK",
  "testError" : "ERROR",
  "success"   : "#007700",
  "error"     : "#FF0000"
}
template
The assessment passed
{d.test:ifEQ(OK):show(.success):elseShow(.error):color(p)}Error color
{d.testError:ifEQ(OK):show(.success):elseShow(.error):color(p)}
Carbone Merge Icon
result
The assessment passed Error color 

Loop and color

The example conditionally changes the text color of the current table row.

In the following example, the Carbone tag {d.tests[i].result:ifEQ(ok):show(#000000):elseShow(d.error):color(row, text)} is used in the template:

data
{
  "error": "#FF0000",
  "tests": [
    { "name": "Security Training","result": "ok" },
    { "name": "Code Auditing","result": "20 Vulnerabilities found" },
    { "name": "Firewall Testing","result": "ok" }
  ]
}
template
Testinfo{d.tests[i].name}{d.tests[i].result} {d.tests[i].result:ifEQ(ok):show(#007700):elseShow(d.error):color(row, text)}{d.tests[i+1]}
Carbone Merge Icon
result
TestinfoSecurity Trainingok Code Auditing20 Vulnerabilities found Firewall Testingok 

Combined colors

The example conditionally changes the background color and text color of the table row.

Two tags are used in the following template:

data
{
  "error": "#ffd9d9",
  "tests": [
    { "name": "Security Training","result": "ok" },
    { "name": "Code Auditing","result": "20 Vulnerabilities found" },
    { "name": "Firewall Testing","result": "ok" }
  ]
}
template
Testid{d.tests[i].name}{d.tests[i].result} {d.tests[i].result:ifEQ(ok):show(#000000):elseShow(#d90000):color(row, text)} {d.tests[i].result:ifEQ(ok):show(#FFFFFF):elseShow(d.error):color(row, background)}{d.tests[i+1]}
Carbone Merge Icon
result
TestidSecurity Trainingok  Code Auditing20 Vulnerabilities found  Firewall Testingok  

Color replacement {bindColor}

We recommend using :color formatter instead of {bindColor} because it is much simpler to use and less error-prone. {bindColor} was the old method in Carbone for managing color.

Compatible with PDF, ODT, ODP, DOCX, and ODS files.

The special bindColor tag allows you to replace a color reference in the template with a new color from your JSON dataset. Usage:

{bindColor(myColorToBind, myFormat) = d.myVar}

Unlike regular tags, {bindColor()} can be placed anywhere in the document, such as the header, footer, or below a repetition [i+1], even if the myVar argument is part of a repetition.

For more details, refer to the example below.

Important Notes:

Supported on:

Simple example with {bindColor}

We recommend using :color formatter instead

Data

{
  "color": "#FF0000", // red
  "color2": "#00FF00", // green
  "color3": "#0000FF" // blue
}

Template

Basic dynamic color

Details:

Result

Basic dynamic color result

Color formats for {bindColor}

We recommend using :color formatter instead

There are 5 color formats:

Microsoft Word exception for {bindColor}

We recommend using :color formatter instead

In Microsoft Word, only a color name can be used to replace the background color of a text.
17 colors are available, which are:

yellow    | green     | cyan      | magenta   | blue | red
darkBlue  | darkCyan  | darkGreen | darkMagenta |  darkRed | darkYellow
darkGray  | lightGray | black     | white     | transparent

You can still use hexadecimal colors for the text and cells backgrounds on Microsoft Word.

Data

{
  "color": "darkYellow",
  "color2": "green",
  "color3": "11BBCC"
}

Template

Microsoft get in background the red color, Word get in background the magenta color and background get the #FFFF00 color

Word color exception

Result

Word color exception result

Loop with {bindColor}

We recommend using :color formatter instead

Each line in a table can be colorized by one color:

Data

{
  "user": [
    {
      "firstname": "Jean",
      "lastname": "Dujardin",
      "color": { "r": 255, "g": 0, "b": 0 }
    },
    {
      "firstname": "Omar",
      "lastname": "Sy",
      "color": { "r": 0, "g": 255, "b": 0 }
    }
  ]
}

Template

The first line get the #0000FF color and the second line get the #00FFFF color. Each line get the color corresponding to the color key in each user object.

Table color

Result

Table color result