Skip to content

Instantly share code, notes, and snippets.

@andreibabor
Created November 21, 2024 21:48
Show Gist options
  • Save andreibabor/8019f82d437ace0c7c8d6a76b2cc4337 to your computer and use it in GitHub Desktop.
Save andreibabor/8019f82d437ace0c7c8d6a76b2cc4337 to your computer and use it in GitHub Desktop.
Pass schema variables to JavaScript - Shopfiy
It seems that the liquify variables must applied outside the {{ javascript }} section. Setting the following after the section html did the trick:
{%- assign row_height = section.settings.row_height -%}
{%- assign spacing = section.settings.spacing -%}
<script>
var rwhgt = {{ row_height | json }};
var spcng = {{ spacing | json }};
</script>
Then I was able to use rwhgt and spcng in the {{ javascript }} section like this:
{% javascript %}
$('.gallery-container').justifiedGallery({
lastRow : 'center',
rowHeight : rwhgt,
margins : spcng
}).on('jg.complete', function () {
$('.image-popup').magnificPopup({
type:'image',
gallery:{enabled: true}
});
});
{% endjavascript %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment