Question

How to display text string with html tags as html

  • 10 August 2021
  • 1 reply
  • 103 views

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 reply

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#string_functions

 

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!

Reply