Skip to content

Instantly share code, notes, and snippets.

@ed-codes
Last active May 11, 2019 09:25
Show Gist options
  • Save ed-codes/54ed4c72cd3bf5bb4cabb61551b1d498 to your computer and use it in GitHub Desktop.
Save ed-codes/54ed4c72cd3bf5bb4cabb61551b1d498 to your computer and use it in GitHub Desktop.
When doing something like <!--video-id:abcabc-->
{% assign video-id = collection.description | split: 'video-id:' | last | split: '-->' | first %}
When you need multiple and dont know how many,
Example images for a slider:
{% assign inaction-images = collection.description | split: '<!--endinaction-->' | first | split: '<img' %}
{% for image in inaction-images %}
{% if forloop.first == true %}
{% comment %}do nothing because this is text/html before the img tag{% endcomment %}
{% else %}
{% assign src = image | split: ' src="' | last | split:'"' | first %}
<a href="javascript:;" class="js-in-action-image" data-sort="0" data-image="{{ src }}" data-zoom-image="{{ src }}">
<img src="{{ src }}" />
</a>
{% endif %}
{% endfor %}
Example, handles grabbed from a list of comments <!--add-on:test-chocolate--><!--add-on:test-liquor-->
{% if product.description contains 'add-on:' %}
{% assign add-on-list = product.description | split: 'add-on:' %}
<div class="add-ons">
{% for add-on in add-on-list %}
{% unless forloop.first %}
{% assign handle = add-on | split: ':' | last | split: '-->' | first %}
<div class="add-on-item">
<p>{{ all_products[handle].title }}</p>
<img src="{{ all_products[handle].featured_image | img_url: '200x' }}" alt="">
</div>
{% endunless %}
{% endfor %}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment