Skip to content

Instantly share code, notes, and snippets.

@gterrill
Last active December 31, 2015 09:49
Show Gist options
  • Save gterrill/7969732 to your computer and use it in GitHub Desktop.
Save gterrill/7969732 to your computer and use it in GitHub Desktop.
Accessing variant config name/value pairs using liquid and formatting date
/* liquid */
{% for variant in product.variants %}
<option data-bta-config="{{ variant.metafields.bookthatapp.config }}">...</option>
{% endfor %}
{% assign configs = variant.metafields.bookthatapp.config | split: '&' %}
{% for config in configs %}
{% assign kvp = config | split: '=' %}
{% if kvp.first == 'start_time' %}
<span class="bta_config_time" data-time="{{ kvp.last }}"></span>
{% endif %}
{% endfor %}
/* js */
$('.bta_config_time').each(function() {
var span = $(this),
t = span.attr('data-time'),
d = new Date(parseInt(t, 10) * 1000),
ld = new Date(d.getTime() + d.getTimezoneOffset() * 60000);
span.text(ld.toLocaleTimeString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment