Knowledge Drop

How do I render HTML from a field in my database?

  • 5 April 2021
  • 0 replies
  • 525 views

Userlevel 5
Badge
  • Looker Staff
  • 172 replies

Last tested: July 2020

Explanation

It is not possible to render HTML tags from the database, mostly because it opens up security risks. The html will just be displayed as plaintext.

The only html that will be rendered is html that a developer writes in LookML. The html docs explain what can be written into LookML.

Using Links is OK

If you have a URL in your database, it can be exposed as a link in Looker with this syntax:

link: {label: "{{ value }}"url: "{{ value }}"}

or alternatively

html: <a href="https://{{ value }}">text you want</a>;;

Novel workaround

There is a novel workaround by formatting links in the database as markdown  [Link_text](url) and then using liquid to parse them out. This allows multiple links and other text to be included as well.

dimension: field_name {  type: string  sql: ${TABLE}.field_name ;;  html: {% assign array = value | split: " " %}          {% for word in array %}            {% if word contains '[' and word contains ']' and word contains '(' and word contains ')' %}              {% assign mdlink = word | split: "](" %}              <a href="{{ mdlink[1] | remove: '[' }}">{{ mdlink[0] | remove: ')' }}</a>            {% else %}            {{ word }}            {% endif %}          {% endfor %} ;;  }

 

This content is subject to limited support.                


0 replies

Be the first to reply!

Reply