5

In a snippet called 'sb' I have this content

{% assign seller_id = 'another_seller_shop_name,test_seller' | split: ',' %} 
{% assign seller_html = 'Another Seller Desc,Seller Description' | split: ',' %}

In the template page - in this case, collection-list I have referenced this snippet

{% include 'sb' %}{% assign seller_id_page = collection.title | replace: ' ','_' | downcase %}

'seller_id_page' will equal to one of the values in 'seller_id'. I just want to be able to return the position of this value, so I can then assign seller_html[x] an index value and render field correctly.

1 Answer 1

8

You will need to loop the array and get the index of the corresponding equality.

In code:

{% for item in seller_id %}
  {% if item == seller_id_page %}
    {% assign position = forloop.index0 %}
    {% break %} 
  {% endif %}
{% endfor %}

{{ seller_html[position] }}

That's the just of it.

1
  • Thanks man, that was incredibly elegant and straight forward. Appreciated. Apr 10, 2020 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.