User Guide Getting Started Help Center Documentation Community Training
New LookML
Old LookML
New LookML
Looker
  
English
Français
Deutsch
日本語
html

Usage

view: view_name {
  dimension: field_name {
    html: <img src="http://www.acme.com/
          product_images/{{ value }}.jpg"/> ;;

  }
}

Hierarchy

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.

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: <ul> <li> value: {{ value }} </li> <li> rendered_value: {{ rendered_value }} </li> <li> linked_value: {{ linked_value }} </li> <li> link: {{ link }} </li> <li> model: {{ _model._name }} </li> <li> view: {{ _view._name }} </li> <li> explore: {{ _explore._name }} </li> <li> field: {{ _field._name }} </li> <li> dialect: {{ _dialect._name }} </li> <li> access filter: {{ _access_filters['company.name'] }} </li> <li> user attribute: {{ _user_attributes['region'] }} </li> <li> query timezone: {{ _query._query_timezone }} </li> <li> filters: {{ _filters['order.total_order_amount'] }} </li> </ul> ;; }

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: acme
• 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 %} <font color="darkgreen">{{ rendered_value }}</font> {% elsif value > 50 %} <font color="goldenrod">{{ rendered_value }}</font> {% else %} <font color="darkred">{{ rendered_value }}</font> {% endif %} ;; }

Exploring Data with the HTML Parameter

Imagine you have a field in your data called status, which gives the status of each order. The possible values for status are:

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' %} <p style="color: black; background-color: lightblue; font-size:100%; text-align:center">{{ rendered_value }}</p> {% elsif value == 'Shipped' %} <p style="color: black; background-color: lightgreen; font-size:100%; text-align:center">{{ rendered_value }}</p> {% else %} <p style="color: black; background-color: orange; font-size:100%; text-align:center">{{ rendered_value }}</p> {% 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' %} <p><img src="http://findicons.com/files/icons/573/must_have/48/check.png" height=20 width=20>{{ rendered_value }}</p> {% elsif value == 'Processing' %} <p><img src="http://findicons.com/files/icons/1681/siena/128/clock_blue.png" height=20 width=20>{{ rendered_value }}</p> {% else %} <p><img src="http://findicons.com/files/icons/719/crystal_clear_actions/64/cancel.png" height=20 width=20>{{ rendered_value }}</p> {% 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 <img> tag, based on the product’s ID:

dimension: product_image { sql: ${product_id} ;; html: <img src="http://www.acme.com/product_images/{{ value }}.jpg" /> ;; }

Maintaining Drill Down Links

To maintain drill down links when formatting output using the html parameter, you can include the HTML tag <a href="#drillmenu" target="_self">. For example:

measure: count { type: count drill_fields: [detail*] html: <a href="#drillmenu" target="_self"> {% if value > 10000 %} <font color="#42a338 ">{{ rendered_value }}</font> {% elsif value > 5000 %} <font color="#ffb92e ">{{ rendered_value }}</font> {% else %} <font color="#fa4444 ">{{ rendered_value }}</font> {% endif %} </a>;; }

Top