html
Usage
view: view_name {
dimension: field_name {
html: ;;
}
}
Possible Field Types
Dimension, Dimension Group, Measure
Accepts
An HTML expression, possibly using Liquid template elements, followed by two semicolons
Definition
The html parameter enables you to specify the HTML that will be contained by a field.
You can also get access to the values that would typically be in the field by using Liquid variables. This allows you to create a number of useful functions, including links to other related Looks, links to external websites, or images.
Using valid HTML
In order to prevent certain security exploits, Looker restricts which HTML tags and attributes may be used, as well as which CSS properties may be used. See our HTML sanitization documentation page for more details.
Liquid variables
The html parameter supports Liquid variables. See the Liquid variables documentation page for information about how to make full use of these variables.
Examples
Here are some examples for using the html field parameter.
HTML formatting only renders in table, table (legacy), and single value chart visualizations and in visualization tooltips when combining multiple fields. Any interactive content placed in a map chart’s tooltip with the html parameter will not be accessible on dashboards that use the new dashboard experience, although it will be accessible on Looks, Explores, and legacy dashboards.
Using Liquid variables in the html parameter
This example shows how most of the Liquid variables would appear in an html parameter. Consider a total_order_amount definition:
measure: total_order_amount {
type: sum
sql: ${order_amount} ;;
value_format: "0.00"
html:
- value: {{ value }}
- rendered_value: {{ rendered_value }}
- linked_value: {{ linked_value }}
- link: {{ link }}
- model: {{ _model._name }}
- view: {{ _view._name }}
- explore: {{ _explore._name }}
- field: {{ _field._name }}
- dialect: {{ _dialect._name }}
- access filter: {{ _access_filters['company.name'] }}
- user attribute: {{ _user_attributes['region'] }}
- query timezone: {{ _query._query_timezone }}
- filters: {{ _filters['order.total_order_amount'] }}
}
The cell value displayed for total_order_amount would look like this:
• value: 8521935
• rendered_value: 8,521,935.00
• linked_value: 8,521,935.00
• link: /explore/thelook/orders?fields=orders.order_amount&limit=500
• model: thelook
• view: orders
• explore: order_items
• field: total_order_amount
• dialect: mysql
• access filter: brettcase.com
• user attribute: northeast
• query timezone: America/Los_Angeles
• filters: NOT NULL
Conditionally format a count according to its values:
measure: formatted_count {
type: count
html:
{% if value > 100 %}
{{ rendered_value }}
{% elsif value > 50 %}
{{ rendered_value }}
{% else %}
{{ rendered_value }}
{% endif %} ;;
}
Exploring data with the html parameter
HTML formatting only renders in table, table (legacy), and single value chart visualizations and in visualization tooltips when combining multiple fields. Any interactive content placed in a map chart’s tooltip with the html parameter will not be accessible on dashboards that use the new dashboard experience, although it will be accessible on Looks, Explores, and legacy dashboards.
Imagine you have a field in your data called status, which gives the status of each order. The possible values for status are:
Paid
Shipped
Returned
While exploring your data, you might want to have a separate background color for each status. This can be done using Liquid html in the html: parameter of a dimension. This would look something like:
dimension: status {
sql: ${TABLE}.status ;;
html: {% if value == 'Paid' %}
{{ rendered_value }}
{% elsif value == 'Shipped' %}
{{ rendered_value }}
{% else %}
{{ rendered_value }}
{% endif %}
;;
}
In your table, this will look like:
You can use the same syntax to add icons or images based on cell values:
dimension: status {
sql: ${TABLE}.status ;;
html: {% if value == 'Shipped' or value == 'Complete' %}
{{ rendered_value }}
{% elsif value == 'Processing' %}
{{ rendered_value }}
{% else %}
{{ rendered_value }}
{% endif %}
;;
}
In your table, this will look like:
Generating product images
Here is an example of how to add the picture of a product into Looker using an tag, based on the product’s ID:
dimension: product_image {
sql: ${product_id} ;;
html: ;;
}
Maintaining drill-down links
To maintain drill-down links when formatting output using the html parameter, you can include the HTML tag . For example:
measure: count {
type: count
drill_fields: [detail*]
html:
{% if value > 10000 %}
{{ rendered_value }}
{% elsif value > 5000 %}
{{ rendered_value }}
{% else %}
{{ rendered_value }}
{% endif %}
;;
}