Building reusable individually customizable sections in liquid

Tourist
87 0 3

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?

0 Likes
New Member
4 0 0

I'm curious about this same thing.  Anyone have any additional thoughts on this?

0 Likes