-
-
Save sidrodev/9df15a91e8d06d0425ab084b3a03f0b3 to your computer and use it in GitHub Desktop.
Photo Variant Alt Build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {%- assign option_index = 'option1' -%} | |
| {%- assign image_matrix = '[ ' -%} | |
| {%- assign image_grid__default = '' -%} | |
| {% for option in product.options_with_values %} | |
| {%- assign option_lowercase = option | downcase -%} | |
| {% if option.name == 'color' %} | |
| {% capture option_index %}option{{ forloop.index }}{% endcapture %} | |
| {% break %} | |
| {% endif %} | |
| {% endfor %} | |
| {%- assign variant_start = current_variant[option_index] -%} | |
| {%- assign options_by_name = product.options_by_name['Color'].values -%} | |
| {%- assign option_color_size = options_by_name.size | times: 1 -%} | |
| {% if option_color_size < 1 %} | |
| {%- capture options_default -%}Default Title{%- endcapture -%} | |
| {%- assign options_by_name = options_default | split: ',' -%} | |
| {%- assign option_index = 'option1' -%} | |
| {% endif %} | |
| {% for color_option in options_by_name %} | |
| {% capture image_matrix %}{{ image_matrix }}{ "option_color": "{{ color_option }}", "images":[ {% endcapture %} | |
| {%- assign comma_needed = false -%} | |
| {% for image in product.images %} | |
| {%- assign image_alt_split = image.alt | split: ':' -%} | |
| {%- assign image_alt_color = image_alt_split[0] | strip -%} | |
| {%- assign image_alt_color_all = image_alt_color | split: ',' -%} | |
| {% if image.attached_to_variant? %} | |
| {%- assign variant_check = image.variants[0] -%} | |
| {% if variant_check[option_index] == color_option %} | |
| {% if variant_start == color_option %} | |
| {% capture image_grid__default %}{{ image_grid__default }}{% include 'loop-thumbnail' %}{% endcapture %} | |
| {% endif %} | |
| {% capture image_matrix %}{{ image_matrix }}{% if comma_needed %}, {% endif %}{ "alt": "{{ image.alt | escape }}", "src": "{{ image.src | img_url: product_thumb_size }}" }{% endcapture %} | |
| {%- assign comma_needed = true -%} | |
| {% endif %} | |
| {% elsif image_alt_color_all contains color_option %} | |
| {% if variant_start == color_option %} | |
| {% capture image_grid__default %}{{ image_grid__default }}{% include 'loop-thumbnail' %}{% endcapture %} | |
| {% endif %} | |
| {% capture image_matrix %}{{ image_matrix }}{% if comma_needed %}, {% endif %}{ "alt": "{{ image.alt | escape }}", "src": "{{ image.src | img_url: product_thumb_size }}" }{% endcapture %} | |
| {%- assign comma_needed = true -%} | |
| {% endif %} | |
| {% endfor %} | |
| {% capture image_matrix %}{{ image_matrix }} ] }{% unless forloop.last %},{% endunless %}{% endcapture %} | |
| {% endfor %} | |
| {% capture image_matrix %}{{ image_matrix }} ]{% endcapture %} | |
| <script type="application/json" id="ImageJSON-{{ product.id }}"> | |
| {{ image_matrix }} | |
| </script> | |
| {% unless image_grid__default != blank %} | |
| {%- capture image_grid__default -%}{%- assign image = product.featured_image -%}{% include 'loop-thumbnail' %}{%- endcapture -%} | |
| {% endunless %} | |
| {{ image_grid__default }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment