Reputation: 1351
If a user click on a button which has class name: '3-col', it will execute the following code: '{% assign products_per_row = "3" %}'.
and if a user click on a '4-col' button, it will execute the following code: '{% assign products_per_row = "4" %}'.
However the code below doesn't work.
I have researched all ways to do that, but I couldn't. Any advice is appreciated. Thanks!
<button class='3-col' onclick="prod3()"></button>
<button class='4-col'onclick="prod4()" ></button>
{% include 'product-loop' with settings.collection_sidebar %}
<script type="text/javascript">
function prod3(){
{% assign products_per_row = "3" %}
}
function prod4(){
{% assign products_per_row = "4" %}
}
</script>
Upvotes: 1
Views: 7906
Reputation: 11
function prod3(){
$(".product-cell").addClass("col-md-3");
}
function prod4(){
$(".product-cell").addClass("col-md-4");
}
Upvotes: 1
Reputation: 124
PS: The site above based on Haravan.com, it just likes Shopify.com (create your own store, customize theme with liquid code... )
Upvotes: 2
Reputation: 15402
This is the sort of thing I find curious about Shopify. There is no simple way to provide interaction between their templates and client side code.
In order to do this you need to do it all client side.
Lets say your products are in divs with class 'product-cell' then your code could be:
function prod3(){
$(".product-cell").css('width', '33.3%');
}
function prod4(){
$(".product-cell").css('width', '25%');
}
then make sure you are including jQuery as an asset in your theme and if this is something you want to make persistent include the use of localStorage or a cookie.
Upvotes: 2