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!
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024