Ad

Is It Possible To Add More Values In A For In Loop Liquid Shopify?

- 1 answer

Here's my code

{% for filter_prefix in filter_prefixes %}
{{ filter_prefix }}
{% endfor %}

There are some values I want to add to the filter_prefixes, example: Type... Can I do it like this?

{% for filter_prefix in filter_prefixes %}
{% filter_prefix = 'Type' %}
{{ filter_prefix }}
{% endfor %}

To list all the filter_prefixes and added the Type value as well.

Please help me with this.

Thank you!

Ad

Answer

Just output the value you want. There is no need to add it to the loop since it is just something you output anyway.

Type
{% for filter_prefix in filter_prefixes %}
   {{ filter_prefix }}
{% endfor %}

Or use the Shopify Array filters split and join. So you join your existing array filter_prefixes into a string, append Type and then split that back into an array.

Ad
source: stackoverflow.com
Ad