简体   繁体   中英

How to pass an array to liquid filters on the fly?

I have tried the following without success:

{{ 'foo', 'bar'   | join: ',' }}
{{ ('foo', 'bar') | join: ',' }}
{{ ['foo', 'bar'] | join: ',' }}

I really don't wanna have another line to pass the array into a variable then use it.

How can I fix this?

The Array needs to come from a Liquid Drop. Liquid does not allow you to assign an Array.

{% assign a = [1,2,3] %}

will NOT work. So even on 2 lines it won't work.

I don't understand your situation but it seems you can just do :) ;) :

{{ 'foo,bar' }}

or maybe something like (one line also :)):

{{ '1|2|3'  | split:'|' | join:',' }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM