0

Is there any way to check if the value of a field is empty or to be more precise value in general link field is empty in Scriban?

Whenever I type the if keyword, it does not register it:

Here is the code:

 {{if (sc_link_text i_child_items 'Build')}}
   {{ sc_beginfield i_child_items 'Build' [['class', 'dropdown-menu-productlink'], ['text', ' ']]}}
      {{ sc_link_text i_child_items 'Build' }}
   {{ sc_endfield }}
 {{else}}
      <p>test</p>
 {{end}}

This code will not work because I still get the empty inner text in a tag

0

1 Answer 1

0

Generally I would use the native null check for models and string check for text.

Example: The following checks that there are SXA tags defined and then joins them together. Take note of first statement to ensure there are tags.

{{ if i_item.SxaTags != "" }}
<span>
Department: 
</span>
{{ tags = [] }}
{{ for i_tag in (sc_followmany i_item "SxaTags") }}
{{ tags[tags.size] = i_tag | sc_field "Title" }}
{{ end }}
{{ tags | array.sort | array.join ", " }}
{{ end }}

Example: If the field is empty when viewing in the raw mode of the content editor then an empty string check is necessary.

{{ if(i_item.herolink != '') }}
{{ i_item.herolink }}
{{ end }}

References

Not the answer you're looking for? Browse other questions tagged or ask your own question.