Liquid doesn't work in HTML/link parameter when value is null

Knowledge Drop

Last Tested: Jul 31, 2019

This issue is specific to how Liquid handles null (nil) values and how they are displayed as "".

Liquid doesn't operate on null values for dimensions and measures. A workaround to have null values rendered by liquid in HTML or used anywhere in Looker is to use COALESCE or IFNULL on the null values to convert them to any non-null value.

Example

where non nulls and nulls will render in HTML differently based on inserted render style, and hyperlink triple dots only show up if not null:

dimension: foo { type: string sql: COALESCE(${field}, "THIS IS NULL") ;; html: {% if value != 'XXX' %} {% else %} {% endif %} ;; link: { url: {% if value != 'THIS IS NULL' %}www.google.com{% else %}{% endif %} label: "Hello World!" } }

Screen Shot 2018-10-19 at 2.39.28 PM.png

The exception is parameter values. This does work for parameters of type: number:

{% if item_to_compare._parameter_value != "NULL" %}
${item_id} = {% parameter item_to_compare %}
{% else %} <some other condition >
{% endif %}

And this works for parameters of type: unquoted:

{% if item_type._parameter_value != "" %} ${item_type} = {% parameter item_type %} {% else %}<some other condition > {% endif %}

This content is subject to limited support.                

Version history
Last update:
‎04-05-2021 09:11 AM
Updated by: