Replacing Collection Title with Metafield in Subcollection Section

Hello. I am using the Maranello 1.7 theme, and want to utilize the “subcollections” function. Instead of the collection’s title, I’d like to display a custom metafield text that I’ve already created. What do I need to change in the Liquid code to display this metafield instead of the title of the subcollection? Thanks in advance!

Hi @TheSpeedDepot ,

Can you post the code of the section? I will check and guide it for you

Hi @TheSpeedDepot ,

You can refer this article to show metafield

https://shopify.dev/docs/api/liquid/objects/metafield

{{ resource.metafields.namespace.key }}

Example:

{{ collection.metafields.custom.test.value  }}

{%- assign subcollections = collection.metafields.custom.subcollections.value -%}
{%- assign subcollections_size = collection.metafields.custom.subcollections | split: ‘,’ | uniq | size -%}

{%- if subcollections -%}
{{ ‘component-card.css’ | asset_url | stylesheet_tag }}
{{ ‘component-pills.css’ | asset_url | stylesheet_tag }}
{{ ‘component-scroller.css’ | asset_url | stylesheet_tag }}
{%- endif -%}

{%- if subcollections and section.settings.layout == ‘slider’ -%}
{{ ‘flickity.css’ | asset_url | stylesheet_tag }}

{%- endif -%}

{% liquid
assign columns = section.settings.columns | at_most: 10
assign layout_classes = ‘grid grid-2-col’

if columns >= 7
assign layout_classes = layout_classes | append: ’ grid-compact-tablet grid-6-col-tablet grid-’ | append: columns | append: ‘-col-desktop-xl’
elsif columns >= 4
assign layout_classes = layout_classes | append: ’ grid-3-col-tablet grid-’ | append: columns | append: ‘-col-desktop’
elsif columns == 2
assign layout_classes = layout_classes | append: ’ grid-2-col-tablet’
else
assign layout_classes = layout_classes | append: ’ grid-3-col-tablet’
endif

if section.settings.layout == ‘slider’
assign layout_classes = layout_classes | append: ’ grid-carousel’
endif
%}

{%- if subcollections -%}

{%- if section.settings.layout == 'slider' -%} {%- endif -%}

{%- unless section.settings.stack_on_mobile or subcollections_size == 1 -%}

{%- endunless -%}
{% for subcollection in subcollections %}
{% render 'card-simple-collection-info', collection: subcollection, use_grid_image: true, title: section.settings.show_title, product_size: section.settings.show_product_size, aspect: section.settings.image_ratio, columns: columns, class: 'card-small' %}
{% endfor %}

{%- unless section.settings.stack_on_mobile or subcollections_size == 1 -%}

{%- endunless -%}

{%- if section.settings.layout == ‘slider’ -%}

{{ 'sections.slideshow.previous_slide' | t }} {% render 'angle', direction: 'left' %} {{ 'sections.slideshow.next_slide' | t }} {% render 'angle', direction: 'right' %}
{%- endif -%}
{%- endif -%}

{% schema %}
{
“name”: “t:sections.main_collection_subcollections.name”,
“settings”: [
{
“type”: “paragraph”,
“content”: “t:sections.main_collection_subcollections.settings.paragraph_1.content”
},
{
“type”: “header”,
“content”: “t:sections.main_collection_subcollections.settings.header_1.content”
},
{
“type”: “select”,
“id”: “image_ratio”,
“label”: “t:sections.all.layout.image_ratio.label”,
“default”: “adapt”,
“options”: [
{
“value”: “adapt”,
“label”: “t:sections.all.layout.image_ratio.options.label_1”
},
{
“value”: “portrait”,
“label”: “t:sections.all.layout.image_ratio.options.label_2”
},
{
“value”: “square”,
“label”: “t:sections.all.layout.image_ratio.options.label_3”
},
{
“value”: “landscape”,
“label”: “t:sections.all.layout.image_ratio.options.label_4”
}
]
},
{
“type”: “checkbox”,
“id”: “show_title”,
“default”: true,
“label”: “t:sections.main_collection_subcollections.settings.show_title.label”
},
{
“type”: “checkbox”,
“id”: “show_product_size”,
“default”: true,
“label”: “t:sections.main_collection_subcollections.settings.show_product_size.label”
},
{
“type”: “header”,
“content”: “t:sections.all.layout.heading”
},
{
“type”: “select”,
“id”: “layout”,
“label”: “t:sections.all.layout.layout.label”,
“default”: “grid”,
“options”: [
{
“value”: “grid”,
“label”: “t:sections.all.layout.layout.options.label_grid”
},
{
“value”: “slider”,
“label”: “t:sections.all.layout.layout.options.label_slider”
}
]
},
{
“type”: “range”,
“id”: “columns”,
“min”: 2,
“max”: 10,
“step”: 1,
“default”: 6,
“label”: “t:sections.all.layout.desktop_columns.label”
},
{
“type”: “checkbox”,
“id”: “stack_on_mobile”,
“default”: false,
“label”: “t:sections.all.layout.stack_on_mobile.label”
}
]
}
{% endschema %}

Hi @TheSpeedDepot ,

Please send me the code of card-simple-collection-info.liquid file and name of metafield, I will guide you to change the code