Liquid arrays question

Bulxar
Explorer
68 1 12

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?

0 Likes
LitExtension
Shopify Partner
1207 154 215

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!

LitExtension - Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes