1
votes

What's the best way to build a reusable DRY section in liquid assuming the store owner wants to choose new options each time the section is reused?

Here are the two methods I can find:

  1. Create a snippet which I can include from any template file, but this won't allow the store owner to customize the settings. Keeps things very DRY but with no customization which defeats the purpose.
  2. Create a section with settings, which includes a reusable snippet. But I need to duplicate this section every time I want to use it on a different page. Requires me to create duplicates of all my sections every time I create a new page.

Option 1:

reusable_snippet.liquid:

<div>
 <h1>I'm a reusable non customizable quote</h1>
</div>

random_page_1.liquid:

{% include 'reusable_snippet' %}

random_page_2.liquid:

{% include 'reusable_snippet' %}

Option 2:

reusable_customizable_snippet.liquid:

<div>
  <h1>{{ section.settings.full_msg_title }}</h1>
</div>

non_reusable_section_1.liquid:

{% include 'reusable_customizable_snippet' %}

{% schema %}
  {
    "name": "Reusable Snippet",
    "settings": [{
  "type": "text",
  "id": "full_msg_title",
  "label": "Full Width Message Title"
}]
  }
{% endschema %}

non_reusable_section_2.liquid:

{% include 'reusable_customizable_snippet' %}

{% schema %}
  {
    "name": "Reusable Snippet",
    "settings": [{
  "type": "text",
  "id": "full_msg_title",
  "label": "Full Width Message Title"
}]
  }
{% endschema %}

Is there some other, better method to create a reusable, individually customizable section?

1

1 Answers

0
votes

It depends of what your section requirements.

If you don't have too many options in that section and your are not using the blocks from it, you can create dynamic blocks, where you will choose each page that the block will be visible on.

If you have too many options or you are using already the blocks, there a still a few ways depending on the information you need to add.

1) Using navigations & pages/articles etc..

Each link can point to a separate page from which you can use the content text or the content and excerpt if it's a blog post.

2) Metafields

Use metafeilds, there is a free APP that support metafields only on the product pages or you can use an extension for the ShopifyFD and use those instead for each page you like to have custom information.


To sum up it all depends on the amount of custom information you plan to edit.