Liquid sandbox

Table of contents

Logic

Available resource

RTE and text input

Check if a product exists and is not hidden

To know if a product exists and is not hidden, compare all_products['product-handle'] with blank.

Liquid


<h4>Good way, using == blank check</h4>
{% unless settings.featured_product == blank or all_products[settings.featured_product] == blank %}
  {{ all_products[settings.featured_product].title }}<br>
{% endunless %}

<h4>Bad way, not using == blank check, all_products['anything'] will always be truthy</h4>
{% if all_products['rubbish-handle'] %}
  {{ all_products['rubbish-handle'].title }}
{% else %}
  No product exists with handle “rubbish-handle”.<br>
{% endif %}

<h4>Good way, using != blank check</h4>
{% if all_products['rubbish-handle'] != blank %}
  {{ all_products['rubbish-handle'].title }}
{% else %}
  No product exists with handle “rubbish-handle”.<br>
{% endif %}

<h4>Another good way, using .empty? check</h4>
{% unless settings.featured_product == blank or all_products[settings.featured_product].empty? %}
  {{ all_products[settings.featured_product].title }}
{% else %}
  No product exists with handle “{{ settings.featured_product }}”.<br>
{% endunless %}


Output

Good way, using == blank check

Camp Stool

Bad way, not using == blank check, all_products['anything'] will always be truthy

Good way, using != blank check

No product exists with handle “rubbish-handle”.

Another good way, using .empty? check

Camp Stool