Reusable blocks with different content on pages

New Member
4 0 0

Hi,

 

I've made a section with different blocks which can be added. The file looks like this (the snippet is not complete, but it gives a general idea)

{% for block in section.blocks %}
  {% case block.type %}
    {% when 'image' %}
      {% include 'image' %}
    {% when 'video' %}
      {% include 'video' %}
    {% when 'text_image' %}
      {% include 'text-image' %}
    {% when 'collection_list' %}
      {% include 'collection-list' %}
  {% endcase %}
{% endfor %}
{% schema %}

{
  "name": "Contentblocks",
  "blocks": [
    {
      "type": "image",
      "name": "Image",
      "settings": [
        {
          "type": "image_picker",
          "id": "logo",
          "label": "Image"
        }
      ]
    }, {
      "type": "video",
      "name": "Video",
      "settings": [
        {
          "type": "url",
          "id": "video",
          "label": "Video URL"
        }
      ]
    }, {
      "type": "collection_list",
      "name": "Collection",
      "settings": [
        {
          "type": "collection",
          "id": "collection",
          "label": "Collection"
        }, {
          "type": "text",
          "id": "title_spacing",
          "label": "Title spacing"
        }, {
          "type": "text",
          "id": "title_narrow",
          "label": "Title narrow"
        }
      ]
    }
  ]
}

{% endschema %}

Then, I've included this section on my homepage:

{% section 'contentblocks' %}

I can now add the blocks to the homepage via the customize button in Shopify. Although, I also want to use the same blocks on the about page. When I add this section to my about page (i've made a specific template for the about), the content is the same as the homepage. I want to use the same type of blocks but different content. Is that possible?

 

I can duplicate the contentblocks section to contentblocks-about and include that on the about page, but if I then want to change / add blocks, I need to do it in different files which is not great either.. 

 

So is there an option to use the same file but with different content?

 

Best wishes

0 Likes