Whitespace and liquid conditionals in labels

I’ve been setting up a field’s label/view_label/group_label using Liquid if/else and noticed that Liquid seems to preserve whitespace. This means that if I lay out the label text with newlines, the view and group labels won’t match existing ones and so they are displayed in the field picker twice.

Does anyone have a way to avoid this?

I’d much prefer to format my code like this:

view_label: "
  {% if _explore._name == 'my_explore' %}
    Some View Label
  {% else %}
    Some Other View Label
  {% endif %}"

rather than this:

view_label: "{% if _explore._name == 'my_explore' %}Some View Label{% else %}Some Other View Label{% endif %}"

It looks like liquid supports the use of some operators to strip whitespace out:

But we need to do some tinkering to Looker to make it work with that syntax— so I wouldn’t try it right now. Seeing if it’s something that’s easy to add…

2 Likes

Hi! Just wanted to follow up to see if you have any sense of when the whitespace control syntax would be available in Looker?

Hey Meera,

I don’t have a timeline yet, it’s on our engineering team’s radar, but will take some testing to make sure there’s nothing in the newer liquid versions that doesn’t jive with our implementation.

I’ll update here if there’s anything!

Great, thanks for the update!