Liquid, JavaScript, themes, sales channels
Can anyone help me do array from dynamic variables data in more elegant way?
section.settings.product_1 and etc. return name of the product of type string/char and blahblahblah
Example in liquid:
{% liquid
assign allProducts = section.settings.product_1 | append: ',' | append: section.settings.product_2 | append: ',' | append: section.settings.product_3 | append: ',' | append: section.settings.product_4 | split: ","
%}
OUTPUT:
["product-one","product-two","product-three","product-four"]
Example in php:
<?php
$allProducts = [
$sectionSettingsProduct1,
$sectionSettingsProduct2,
$sectionSettingsProduct3,
$sectionSettingsProduct4
];
?>
Example in python:
allProducts = [sectionSettingsProduct1, sectionSettingsProduct2, sectionSettingsProduct3, sectionSettingsProduct4]
Example in JS:
var allProducts= [sectionSettingsProduct1, sectionSettingsProduct2, sectionSettingsProduct3, sectionSettingsProduct4];
So is there a more like python || php || js version instead of that liquid garbage code?
Hi @Bulxar,
It's not possible, you can just create array with split. Refer https://shopify.github.io/liquid/basics/types/#array
Hope it helps!
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024