Last active
December 31, 2015 09:49
-
-
Save gterrill/7969732 to your computer and use it in GitHub Desktop.
Accessing variant config name/value pairs using liquid and formatting date
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
/* 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