Save color in parameter for reuse

Is there a possibility in Looker to save colors or other stuff in a parameter or variable, to easily reuse it.

Color is just an example, it would be nice to have this possibility with other variables as well.

In our LookML code we have this kind of code:

  dimension: category {
type: string
sql: ${TABLE}.Category ;;
html:
{% if value == 'Severe Risk' %}

<p style="color: white; background-color:#ea5667; font-size:100%; text-align:center; border:3px; border-style:solid; border-color:#FFFFFF">{{ rendered_value }}</p>

{% elsif value == 'Risk Country' %}

<p style="color: white; background-color:#ed6e54; font-size:100%; text-align:center; border:3px; border-style:solid; border-color:#FFFFFF">{{ rendered_value }}</p>

{% elsif value == 'Low Risk Country' %}

<p style="color: white; background-color:#a0c969; font-size:100%; text-align:center; border:3px; border-style:solid; border-color:#FFFFFF">{{ rendered_value }}</p>

{% else %}

<p style="color: black; background-color:#e8e9ec; font-size:100%; text-align:center; border:3px; border-style:solid; border-color:#FFFFFF">{{ rendered_value }}</p>

{% endif %}

;;
}

The coloring used in this HTML is repeated at several places. 

It would be nice if this could be stored in a parameter, so when we update it to another color, it gets updated in all places where it’s used.

Solved Solved
0 6 529
1 ACCEPTED SOLUTION

Hi @mathias_luyten,

I’d suggest making use of constants in your manifest file.

constant: negative_format {
value: "{% if value < 0 %}<p style=\"color:red; \">({{rendered_value}}){% else %} {{rendered_value}} {% endif %}"
}
measure: total_amount {
type: sum
value_format_name: usd
sql: ${amount} ;;
html: @{negative_format} ;;
}

Here’s the documentation

Hope it helps!

View solution in original post

6 REPLIES 6
Top Labels in this Space
Top Solution Authors