【问题标题】:Repeatable Sections on Secondary Pages in ShopifyShopify 中辅助页面上的可重复部分
【发布时间】:2018-04-10 13:53:49
【问题描述】:

我有一个部分 .liquid 模板,我希望能够在每次具有不同内容的非主页模板上重复多次。

我能找到的唯一解决方案是使用相同的代码创建多个文件(即 section/file-1.liquid、section/file-2.liquid)。但是,从可维护性的角度来看,这远远不够理想。

基本上,我希望能够在每次调用该部分时使用独特的内容执行以下操作:

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

让我的部分文件做这样的事情:

{% 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>

该部分会在一个页面上出现两次,然后在另一个页面上再次出现,每个页面都有不同的内容。

这可能吗?有没有办法做到这一点?

【问题讨论】:

    标签: shopify liquid


    【解决方案1】:

    根据您的部分内容,这可能是可能的。

    如果您不使用该部分中的blocks,您可以创建一个部分并将所有块作为单独的部分循环。又名

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

    如果您使用该部分的块来显示一些动态块,那么您没有太多选择,您必须将逻辑切换到元字段或其他一些自定义方法。

    【讨论】:

    • 元字段是否可以通过管理界面进行编辑?看起来不是这样,但是关于元字段的文档似乎并不那么广泛。元字段可以添加到页面吗?
    猜你喜欢
    • 2018-11-03
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2018-03-20
    相关资源
    最近更新 更多