Console

Canopy Block Settings

Learn about the setting types available for Canopy Block templates

Settings define the fields content editors fill in for each Canopy Block. You declare them in the settings array of a block template's config section, and their values are available in the template section through the settings variable.

All setting types share these attributes:

AttributeDescriptionData Type
nameThe setting identifier, used to access the value in the template sectionString
typeOne of the setting types documented belowString
label (optional)The field label shown in the Canopy editor. Generated from the name if omittedString
default (optional)The value used until an editor provides oneMixed
help (optional)A short hint shown as an info icon tooltip beside the field label. See Help and descriptionsString
description (optional)Helper text rendered underneath the input. See Help and descriptionsString
tab (optional)The editor tab the setting appears under. See Tabs and groupsString
group (optional)The collapsible group the setting appears in. See Tabs and groupsString

Tabs and groups

Blocks with many settings can organize them so editors are not shown everything at once. Both attributes are optional and only affect the editing form — they change nothing about how you access values in the template section.

Give settings a tab to split the form into tabs. Tabs appear in the order they are first used, and any settings without a tab are gathered under a General tab. The form only shows tabs when at least one setting declares one.

Give consecutive settings a group to place them under a labelled divider. Groups are open by default, and editors can collapse them.

{
    "title": "Hero",
    "name": "hero",
    "settings": [
        { "name": "title", "type": "text", "tab": "Content" },
        { "name": "description", "type": "textarea", "tab": "Content" },
        { "name": "background", "type": "color", "tab": "Style", "group": "Colors" },
        { "name": "text_color", "type": "color", "tab": "Style", "group": "Colors" },
        { "name": "custom_class", "type": "text", "tab": "Style", "group": "Advanced" }
    ]
}

This config gives the block a Content tab with two fields, and a Style tab where the color settings sit under a Colors group and the class setting under an Advanced group.

Help and descriptions

Every setting type accepts two optional strings for guiding editors. Like tabs and groups, they only affect the editing form and change nothing about the value in the template section.

  • help is a short hint shown as an info icon tooltip beside the field label.
  • description is muted helper text rendered underneath the input.

Use help for a quick clarification editors may not need every time, and description for guidance that should always be visible:

{
    "name": "subtitle",
    "type": "text",
    "help": "Shown under the page title.",
    "description": "Keep it under 80 characters so it fits on one line."
}

Text

type: text

A single line of plain text. The value is a String, with "New text" as the built-in default.

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the inputString
<p>{{ settings.subtitle }}</p>

Textarea

type: textarea

Multiple lines of plain text. The value is a String, empty by default.

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the inputString

Richtext

type: richtext

Formatted text edited with a rich text editor. The value is an HTML String, so output it with the raw filter:

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the inputString
<div class="prose">{{ settings.body|raw }}</div>

Select

type: select

A dropdown of predefined options. The value is the selected option's value as a String.

AttributeDescriptionData Type
optionsAn array of options, each with a value and an optional labelArray
{
    "name": "alignment",
    "type": "select",
    "options": [
        { "value": "left", "label": "Left" },
        { "value": "center", "label": "Center" },
        { "value": "right", "label": "Right" }
    ],
    "default": "center"
}

Radio

type: radio

A set of radio buttons. Works exactly like Select, with the same options attribute, but shows every option at once in the editor.

Checkbox

type: checkbox

A single on or off toggle. The value is a Boolean, false by default.

{% if settings.show_title %}
  <h2>{{ settings.title }}</h2>
{% endif %}

File

type: file

A file picked from the site's assets. The value is an object describing the file.

AttributeDescriptionData Type
accept (optional)A MIME type filter for the picker, such as application/pdfString
Value propertyDescriptionData Type
pathThe file URLString
nameThe filenameString
typeThe file's MIME typeString
sizeThe file size in bytesNumber
{% if settings.brochure.path %}
  <a href="{{ settings.brochure.path }}" download>{{ settings.brochure.name }}</a>
{% endif %}

URL

type: url

A link with editable text and target. The value is an object.

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the inputString
Value propertyDescriptionData Type
urlThe link URLString
textThe link textString
targetThe link target, _self or _blankString
<a href="{{ settings.cta.url }}" target="{{ settings.cta.target }}">{{ settings.cta.text }}</a>

Date

type: date

A date picker. The value is a formatted date String.

AttributeDescriptionData Type
format (optional)The date format to store and output. Defaults to Y-m-dString

Color

type: color

A color picker. The value is a hex color String, #000000 by default.

<section style="background-color: {{ settings.background }}">...</section>

Heading

type: heading

A heading with editable text and an editable HTML element. The value is an object.

AttributeDescriptionData Type
elements (optional)The elements editors can choose from, each with a value and an optional label. Defaults to h1 through h6Array
Value propertyDescriptionData Type
valueThe heading textString
elementThe HTML element, such as h2String
<{{ settings.heading.element }}>{{ settings.heading.value }}</{{ settings.heading.element }}>

Number

type: number

A numeric input. The value is a Number.

AttributeDescriptionData Type
min (optional)The minimum allowed valueNumber
max (optional)The maximum allowed valueNumber
placeholder (optional)Placeholder text shown in the inputString

List

type: list

A repeatable list of text items. The value is an Array of Strings, empty by default.

<ul>
  {% for item in settings.features %}
    <li>{{ item }}</li>
  {% endfor %}
</ul>

Media Sources

type: media-sources

A list of media files for HTML5 audio and video elements. The value is an Array of objects, each with a url and a type (the MIME type).

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the inputString
<video controls>
  {% for source in settings.video_sources %}
    <source src="{{ source.url }}" type="{{ source.type }}" />
  {% endfor %}
</video>

Collection

type: collection

A collection picked from the site's collections. Use it when a block renders whatever a collection holds, and the editor decides which collection feeds it, such as a block that shows the latest items from any collection they choose. The editor sees a dropdown of the site's collections.

Collection settings use only the base attributes. default may be a collection handle String, and placeholder sets the dropdown's placeholder text.

AttributeDescriptionData Type
placeholder (optional)Placeholder text shown in the dropdownString

The value is null while no collection is selected, or when the selected collection has been deleted. Otherwise it is an object:

Value propertyDescriptionData Type
idThe collection's unique idString
objectAlways collectionString
nameThe collection nameString
handleThe collection handleString
entriesThe collection's entriesArray

Each entry in entries exposes its field values under their field names, such as entry.title or entry.image, along with id, created_at, and updated_at.

{
    "name": "source",
    "type": "collection",
    "label": "Collection",
    "help": "All entries of the chosen collection are rendered."
}

Always check the value before using it. A collection that was never selected, or was deleted after being selected, resolves to null rather than erroring, so an unguarded template renders blank fields.

Entry

type: entry

One or more entries hand-picked from a collection. Use it when the editor chooses specific content rather than a whole collection: a featured item, a set of related items, or a hand-picked gallery.

AttributeDescriptionData Type
collection (optional)Hard-declares the source collection by handle. The editor's collection dropdown is hidden and only this collection's entries can be picked. At render time this always wins over stored dataString
default_collection (optional)Pre-selects a collection in the editor, but the editor can switch to another. Switching clears the picked entries. Ignored when collection is setString
multiple (optional)Whether editors pick a single entry or several. false shows a single entry dropdown, true a multi-select with add and remove. Defaults to falseBoolean
min / max (optional)Bounds for the number of entries when multiple is true. The editor enforces maxNumber
display_field (optional)The entry field shown as the label while picking. Defaults to the entry's first non-empty text fieldString
placeholder (optional)Placeholder text shown in the entry dropdownString

Use collection whenever the block is designed around one specific collection. It gives editors a simpler picker with no collection dropdown, and it guarantees the template's assumptions about which entry fields are available.

display_field only changes the labels in the editor's picker. It never affects what the template receives or renders.

Rendering entries

Each entry exposes its field values under their field names, along with id, created_at, and updated_at, just like the entries of a Collection setting.

With multiple off, the value is the picked entry, or null when nothing is picked or the entry or its collection was deleted:

{% if settings.featured %}
  <h3>{{ settings.featured.title }}</h3>
  <img src="{{ settings.featured.image }}" alt="{{ settings.featured.title }}">
{% endif %}

With multiple on, the value is an array of entries in the exact order the editor picked them, so you can rely on that order for layout. Deleted entries are skipped, and the array is empty when nothing is picked:

{% if settings.related|length > 0 %}
  {% for item in settings.related %}
    {{ item.title }}
  {% endfor %}
{% endif %}

As with collections, guard your output: check single entries with if, and check arrays with the length filter. Deleted content resolves to null or an empty array rather than erroring.

Common configurations

Lock the setting to one collection, and label entries by a specific field while picking:

{
    "name": "featured",
    "type": "entry",
    "label": "Featured product",
    "collection": "products",
    "display_field": "sku"
}

Pre-select a collection but let the editor switch to another:

{
    "name": "highlight",
    "type": "entry",
    "label": "Highlight",
    "default_collection": "products"
}

Let the editor pick up to four entries:

{
    "name": "related",
    "type": "entry",
    "label": "Related items",
    "collection": "products",
    "multiple": true,
    "max": 4
}

Entries and collections are stored by collection handle and entry id. Renaming a collection's handle breaks existing block data that points at it, so settle on handles before editors start filling in blocks.

Last updated on

On this page