Skip to content

Instantly share code, notes, and snippets.

@carbone
Created Feb 18, 2021
Embed
What would you like to do?
{% if shop.metafields.custom_fields["tabs"] != blank %}
<div id="custom-fields-tabs">
<ul class="tabs">
{% for item in shop.metafields.custom_fields["tabs"] %}
{% assign class = '' %}
{% if forloop.first == true %}
{% assign class = 'current' %}
{% endif %}
<li class="tab-link {{ class }}" data-tab="tab-{{ forloop.index0 }}"><strong>{{ item["tab_label"] }}</strong></li>
{% endfor %}
</ul>
<!-- end of tab labels -->
{% for tab in shop.metafields.custom_fields["tabs"] %}
{% assign class = '' %}
{% if forloop.first == true %}
{% assign class = 'current' %}
{% endif %}
<div id="tab-{{ forloop.index0}}" class="tab-content {{ class }}">
{% if tab['format'] == 'table'%}
<table>
{% for tab_data in tab["fields"] %}
{% assign metafield_key = tab_data["key"]%}
{% assign metafield_namespace = tab_data["namespace"]%}
{% if product.metafields[metafield_namespace][metafield_key] != null %}
<tr id={{ metafield_key }}><td><strong>{{ tab_data["label"] }}</strong></td><td>{{ product.metafields[metafield_namespace][metafield_key] }}</td></tr>
{% endif %}
{% endfor %}
</table>
{% else %}
{% for tab_data in tab["fields"] %}
{% assign metafield_key = tab_data["key"] %}
{% if product.metafields.custom_fields[metafield_key] != null %}
{% if tab_data["label"] != blank %}
{% assign label = tab_data["label"] | append: ": " %}
{% else %}
{% assign label = ''%}
{% endif %}
<div id={{ metafield_key }}><strong>{{ label }} </strong>{{ product.metafields.custom_fields[metafield_key] }}</div><br />
{% endif %}
{% endfor %}
{% endif %}
</div><!-- end of tab -->
{% endfor %}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment