Skip to content

Instantly share code, notes, and snippets.

@zachharkey
Last active September 22, 2016 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachharkey/ee3396a1a218fe9d3a7bac5b26e4bf60 to your computer and use it in GitHub Desktop.
Save zachharkey/ee3396a1a218fe9d3a7bac5b26e4bf60 to your computer and use it in GitHub Desktop.
Liguid logic for displaying specific "ship" messages depending on product tag

Lead time messages based on tags

Requirements from client

    So the tags are in all caps and the corresponding messages to go with are below each 
    
    SHIP 1 
    1-2 week lead time
    
    SHIP 2 
    2-6 week lead time 
    
    SHIP 3 
    Extended lead time 

Here is the necessary logic in 'liquid' code

{% if product.tags.size > 0 %}
    {% for tag in product.tags %}
      
      {% case tag %}
        {% when 'SHIP 1' %}
          <p class="lead-time mt1 orange">
            1-2 week lead time
          </p>
        {% when 'SHIP 2' %}
          <p class="lead-time mt2 orange">
            2-6 week lead time 
          </p>
        {% when 'SHIP 3' %}
          <p class="lead-time mt1 orange">
            Extended lead time 
          </p>
        {% else %}
           <!-- No message -->
      {% endcase %}

    {% endfor %}
{% endif %}

The above code lives in snippets/lead-time.liquid and is included in product.liquid with {% include 'lead-time' %}. You can edit the code here.

Here's the result

Screenshot of resulting message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment