Accentuate Custom Fields
  • Welcome!
  • Introduction
    • Getting started with ACF
    • Field scopes
    • How to show fields in your storefront
  • Dashboard
    • Reference Manager
      • Creating a new reference within Reference Manager
    • Filter & Group
      • Filter editor
      • Filter usage
    • Activity log
    • App settings
  • Field Definitions
    • Fields & Sections
    • Deciding on a field type
    • ACF Field types
      • Text
      • Markdown text
      • HTML
      • Checkbox
      • Selection
      • Tags
      • Number
      • Date
      • Color
      • Media v1 (legacy)
      • Media v2
      • Custom Object (JSON)
      • Multi-language Text
      • Reference fields
      • References to Global fields
    • Shopify Field types
      • Shopify » Single line text
      • Shopify » Multi-line text
      • Shopify » Boolean
      • Shopify » Color
      • Shopify » Custom objects (JSON)
      • Shopify » URL
      • Shopify » Date
      • Shopify » Date and Time
      • Shopify » Integer
      • Shopify » Decimal
      • Shopify » Weight
      • Shopify » Volume
      • Shopify » Dimensions
      • Shopify » Reference fields
    • Automatic tagging
    • Large sets
    • Field contexts
    • Field context filters
    • Copy and paste fields
    • Change field name and type
    • Import existing fields
    • Linking multiple stores
  • The Editor
    • Using the editor
    • Promote fields to sidebar
    • Layouts
    • Hide from search
    • Repeatable fields
    • Version control
    • Update value on order creation
  • Bulk Import & Export
    • Export custom field values
    • Import custom field values
    • Metaobject export / import
  • METAOBJECTS
    • What are Metaobjects?
    • Metaobject Definitions
    • Metaobject instances / values
    • Displaying Metaobjects on your storefront
    • Metaobject export / import
  • THEME EXTENSIONS
    • SEO keywords
    • Sticky promo bar
    • Products promotion
  • Liquid Guides
    • Learning Liquid
    • Resize & crop images
    • Check for empty values
    • Access field definitions
    • Order notifications
    • Allow customers to change their field values
  • OTHER
    • Webhooks
    • API
      • Access to custom fields
      • Endpoints
  • Help
    • FAQ
      • Why are one of my products no longer showing in my reference field?
      • I have multiple products/variants with the same name
      • How do I make changes to my field values in bulk?
      • I added a new field definition but it is not showing in my storefront
      • How do I copy my field setup to another store?
      • My fields are still showing after I have deleted their field definition
      • Why are none of my fields showing in the editor?
      • My newly created object in Shopify is not available in ACF
      • Reference lists are empty?
      • Why am I seeing a "value cannot exceed 100,000 characters" error when saving?
      • Why can't I name my field "first", "last" or "size"?
    • Need help?
  • Product
    • Changelog
    • Feedback & Suggestions
Powered by GitBook
On this page
  • Limiting the number of occurrences in a repeatable field
  • How to loop over repeatable fields
  • How to loop over repeatable sections
  • Changing an existing field to be repeatable
  1. The Editor

Repeatable fields

PreviousHide from searchNextVersion control

Last updated 10 months ago

Single fields or blocks of fields (sections) can be defined as "repeatable".

The basic Shopify » ... types cannot be repeatable due to their inherited limitations. However, the Shopify » ... (List) types are repeatable by nature

This means that rather than having a 1:1 relation between a field and its value (depending on the field's type), a field's value can become an array of said values. The actual number of occurrences within that array doesn't need to be known when you define the field, but rather the number of values is defined dynamically by you when editing the field for a specific object. Examples:

  • Ingredients for an article about a certain recipe

  • Features or specifications for a specific product

  • Set of questions and answers for an FAQ list on a page

The ACF editor will show you each field's or section's value index ("1 of 2", "3 of 10" etc.) next to each field or section to help you keep track of the defined values:

Use the controls to move fields or entire sections up or down in sequence or to either remove the occurrence or to 'repeat' it. Repeating a field or a section will insert another occurrence after the position of the element is repeated.

Limiting the number of occurrences in a repeatable field

By default, you can repeat a repeatable element as many times as you like.

You can optionally set a limit as to how many occurrences a field (or a section) may contain by selecting a limit other than the default "No limit" when defining the field. If a limit is e.g. 5, the ACF editor will stop you from repeating that field (or section) when the limit is reached.

How to loop over repeatable fields

Arrays stored in Shopify Metafields are automatically converted to an iterable array when used from Liquid. This makes it easy to loop over the values as well as access individual items as shown here for a simple list of ingredients:

<p>Ingredients:</p>  
<ul>
{% for ingredient in product.metafields.accentuate.ingredients %} 
  <li>{{ ingredient }}</li>
{% endfor %} 
</ul>

How to loop over repeatable sections

Now when you need to loop over the contained fields for an entire section, it's important to know that sections are not custom fields in their own right, so you cannot reference them directly via Liquid. Rather we need to select one of the fields to do the loop and then reference the other field(s) via the index provided by Liquid:

<h1>Ingredients:</h1>  
{% for header in product.metafields.accentuate.header %} 
  <h3>{{ header }}</h3>
  <p>{{ product.metafields.accentuate.measurement[forloop.index0] }}</p>
{% endfor %} 

Be sure to loop over a field, that you know will have content. If all occurrences of a repeatable field are empty, the Metafield will not exist and your loop will not execute

Changing an existing field to be repeatable

You can define an existing non-repeatable field with values already in place to be repeatable, but the underlying Metafields won't become an array before any value(s) are saved via the ACF editor. Reversely, if you remove the repeatable setting from a field where multiple values have already been saved, the underlying Metafield won't revert from an array to a string before a new value is saved via the ACF editor - the editor will suggest the value from the first occurrence as the default.

When defining a section as being repeatable, all fields belonging to that section are marked repeatable as well. This is what you'd expect, but removing an already set "repeatable" checkmark for a section does not remove the "repeatable" setting for the individual fields as you might expect. They will revert to being repeatable on a single-field basis and you'll have to edit them individually to match your needs. This "quirk" has to do with ACF being backward compatible with individual fields defined as repeatable before it was possible to do it for sections as well

You can use like first, last, size, sort, sort_natural, uniq, etc. to manipulate the arrays stored in the Metafields and thereby control how the values are presented via the storefront. Please note that a repeatable field stored as an array can still contain multiple selections of values in each of the array's elements either separated with "pipe" symbols ("|") or as individual arrays in their own right.

Liquid's array filters