Skip to content

Instantly share code, notes, and snippets.

@carbone
Last active June 4, 2018 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbone/b82f8ab17dd5a82c6c8a119611a4becb to your computer and use it in GitHub Desktop.
Save carbone/b82f8ab17dd5a82c6c8a119611a4becb to your computer and use it in GitHub Desktop.
strip liquid image preserve tag
If the alt tag is empty...
{% if product.metafields.custom_fields["test_background_image"] contains 'alt=""' %}
{% assign image_url = product.metafields.custom_fields["test_background_image"] | remove: '<img src="' | remove: '" alt="" typeof="foaf:Image" />' %}
Image URL: {{ image_url }}
{% else %}
If the alt tag has a value...
{% assign v1 = product.metafields.custom_fields["test_background_image"] | remove: '<img alt="' | split: '" src="'%}
{% assign alt = v1[0] %}
{% assign image_url = v1[1] | remove: '" typeof="foaf:Image" />'%}
Image URL: {{ image_url }}
Alt Tag: {{ alt }}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment