Skip to content

Instantly share code, notes, and snippets.

@carbone
Last active February 5, 2018 19:38
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 carbone/ce465d0ef345e094ce566e5459fe7d3d to your computer and use it in GitHub Desktop.
Save carbone/ce465d0ef345e094ce566e5459fe7d3d to your computer and use it in GitHub Desktop.
Add this file to Snippets
{% comment %}
Help Article
https://customfields.zendesk.com/hc/en-us/articles/360000622771
Theme Files
/assets/custom-fields-tabs.js
/assets/custom-fields-tabs.scss.css
theme.liquid <head> section.
product.liquid or product-template.liquid, changes made to include this file.
{% endcomment %}
{% assign tabs = shop.metafields.custom_fields["tab_definition"] | split: '|' %}
{% if tabs %}
<div id="custom-fields-tabs">
<ul class="tabs">
{% for tab_info in tabs %}
{% assign tab_item = tab_info | split: '=' %}
{% assign tab_index = tab_item[0] %}
{% assign tab_label = tab_item[1] %}
{% if product.metafields.custom_fields[tab_index] != null %}
{% if first_label_loop == null %}
{% assign first_label_loop = true %}
{% endif %}
{% assign class = '' %}
{% if first_label_loop == true %}
{% assign first_label_loop = false %}
{% assign class = 'current' %}
{% endif %}
<li class="tab-link {{ class }}" data-tab="{{tab_index}}">{{ tab_label }}</li>
{% endif %}
{% endfor %}
</ul>
{% assign tab_item = '' %}
{% assign tab_index = '' %}
{% for tab_info in tabs %}
{% assign tab_item = tab_info | split: '=' %}
{% assign tab_index = tab_item[0] %}
{% if product.metafields.custom_fields[tab_index] != null %}
{% if first_contents_loop == null %}
{% assign first_contents_loop = true %}
{% endif %}
{% assign class = '' %}
{% if first_contents_loop == true %}
{% assign class = 'current' %}
{% assign first_contents_loop = false %}
{% endif %}
<div id="{{ tab_index }}" class="tab-content {{ class }}">
{{ product.metafields.custom_fields[tab_index] }}
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment