How to display text string with html tags as html

I have a simple string dimension that contains html tags. When I display in Looker it treats the dimension as a text string and does not know the html tags in the string is actually html.

Hoe can I get the dimension to recognize and display using the html tags?

I tried to add the HTML parameter like:

  dimension: solution {
    type: string
    sql: ${TABLE}.string ;;
    html: {{ value }} ;;
  }

But it still just displays all the tags as if were just part of the text string.

Thanks!

1 2 2,251
2 REPLIES 2

Hi there. I’m still really new to Looker, but I spent a few hours last week working with HTML trying to get images to display.

If the HTML tags are in the string, I would guess that Looker reads it all as a string. Try with the HTML tags in the html block surrounding the value you want to use:

dimension: solution_2 {
    type: string
    sql: ${TABLE}.string ;;
    html: <img src= "{{ value }}"/ >;;
  }

Note that {{value}} will read whatever the sql block returns. If the HTML tags are all stored in the string, you will need to extract the value in a separate dimension prior to using and then reference that new dimension in the sql block. You can find some helpful string functions here: https://docs.looker.com/exploring-data/creating-looker-expressions/looker-functions-and-operators#st...

For help using HTML tags (I used this for displaying images) https://docs.looker.com/reference/field-params/html?version=21.12&lookml

From my own recent experience, I suggest creating a few dimensions and altering the code you are trying so that you can compare what works and what does not. There is nothing more frustrating than to get it working and then breaking it because you want to try something else :nerd:

I hope this helps!

In the solution you give, you suppose that they are adding the html in their database, which is not necessarily the case. 
This solution doesn't help in cases where the html is already in the source data (ex: if you're pulling it from a website). In my case, I want to be able to display the html that I'm getting from my source data. 

There is no actual solution for this problem and there probably never will be, as allowing the display of html code directly inside looker would pose a security threat (html injections).

Top Labels in this Space
Top Solution Authors