I have a section on a collection template that calls in 4 collections. Schema looks like this:
{ "type": "collection", "id": "set_col_1", "label": "Set builder 1" }, { "type": "collection", "id": "set_col_2", "label": "Set builder 2" }, { "type": "collection", "id": "set_col_3", "label": "Set builder 3" }, { "type": "collection", "id": "set_col_4", "label": "Set builder 4" },
I want to print out the selected collection title, url, and featured image. I realize I could do this manually for each item, but for the sake of learning, I want to iterate.
I have this:
{% assign set_col_count = 0 %} {% for i in (1..4) %} {% assign set_col_setting = "set_col_" | append: i %} {% if collections[section.settings.set_col_1] != blank %} {% assign set_col_count = set_col_count | plus: 1 %} {% endif %} {% endfor %} {% if set_col_count > 0 %} <div class="Grid"> {%- for i in (1..4) -%} {%- assign set_col_setting = "set_col_" | append: i -%} {%- assign collection = collections[section.settings.set_col_setting] -%} <div class="Grid__Cell 1/2--desk"> {{ collection }} <!--Prints EmptyDrop --> {{ collection.title }} <!--Prints nothing --> {{ set_col_setting }} <!-- Prints text set_col_1... set_col_4 --> </div> {%- endfor -%} </div> {% endif %}
I am getting an EmptyDrop. I am not sure how to get the collection object. Obviously something is wrong in `{%- assign collection = collections[section.settings.set_col_setting] -%} `
What am I missing? If I jump out of this loop and just do, say, `assign collection = collections[section.settings.set_col_3]` and print `collection.title` , it works as expected.
User | Count |
---|---|
734 | |
143 | |
102 | |
64 | |
36 |