0
votes

I have a section .liquid template that I want to be able to repeat multiple times on a non-homepage template with different content each time.

The only solution I was able to find would be to creating multiple files (i.e. section/file-1.liquid, section/file-2.liquid) with the same code. However, from a mainainablity standpoint this is far less than ideal.

Basically, I want to be able to do the following with unique content each time the section is called:

<section class="grid-x">
    {% for index in (1..2) %}
        <div class="cell small-12 medium-large-6">
            {% section 'custom-section' %}
        </div>
    {% endfor %}
</section>

And have my section file do something like this:

{% assign list = section.blocks %}

<section>
    {% if section.settings.title %}
        <h2>{{ section.settings.title }}</h2>
    {% endif %}

    <ul>
        {% for item in list %}
            {% if item.settings.title %}
                <li>
                    {% if  item.settings.icon %}
                        <span class="icon-area" aria-hidden="true">
                            <i class="icon icon-{{ item.settings.icon }}"></i>
                        </span>

                        <span>{{ item.settings.title }}</span>
                    {% endif %}
                </li>
            {% endif %}
        {% endfor %}
    </ul>
</section>

And that section to appear twice on one page and again on another page with different content in each.

Is this possible? Is there any way to do this?

1

1 Answers

0
votes

Depending on you section content it might be possible.

If you don't use the blocks from the section you can create a single section and loop all of the blocks as separate sections. A.k.a

{% for block in section.blocks %}
...
{% endfor %}

If you are using the blocks of that section to show some dynamic blocks, than you don't have much of choice and you must switch your logic to metafields or some other custom approach.