Switch field

Updated

The Switch field is a Collection field that is primarily used as a filtering tool. A switch is a field type which can have either of two values: Yes or No.

The Switch field is a Collection field that is primarily used as a filtering tool. A switch is a field type which can have either of two values: Yes or No. Collaborators can toggle a switch on or off to specify, for example, if a blog post “is featured.” The switch field can be used to filter Collection lists. You can even sort a list using switches. And one of the best ways to use a switch field is by setting conditional visibility on elements in Collection lists and Collection pages.

Common Uses
  • Want to display only non-profits? Create a “Non-profit?” switch.
  • Want to display featured articles? Create a “Featured?” switch.
  • Want to hide specific items until they are ready to be displayed in your site? Create a “Hidden?” switch.
  • Want to show an “On Sale” label only for selected items? Create an “Is On Sale?” switch.

Creating a switch field

A switch field can be added to a new or existing Collection. In Collection settings, click on New Field and then choose the Switch field.

Pro Tip

Note

The default value for a switch is “No”. So, when you create a switch, consider labeling it with a question that will in most cases have “No” as answer. So, you’ll only switch it on for the few “Yes” answers. For example, if you want to hide only a few of a hundred blog posts, create a switch called “hidden” instead of “shown”.

Setting a switch value

Whether you’re creating a new item in the CMS from the Designer or the Editor, you can set a switch on or off by simply toggling it to Yes or No.

Filtering a Collection list using the switch field

If you want to create a Collection list that only displays items that have a specific switch set to Yes, like a Collection list of featured posts, you can create a filter that will do that:

  1. Select the Collection list you want to filter
  2. Go to the Settings panel (D)
  3. Add a Filter under Collection List Settings
  4. Select your switch field in the first dropdown
  5. Choose Is On in the second dropdown
  6. Click Save

The filter rules that you can use with the link field and values are:

  • Is On - looks for CMS items that have set the switch On for this switch field
  • Is Off - looks for CMS items that have left the switch Off for this switch field

Learn more about filtering collection lists.

Sorting a Collection list using the switch field

Sometimes, you don’t want to exclude Collection items in a Collection list, but you would like to display specific items first, followed by less important items. So, instead of using a filter, you can specify a sort order using a switch field:

  1. Select the Collection list you want to filter
  2. Go to the Settings panel (D)
  3. Add a Sort order under Collection List Settings
  4. Select your switch field in the first dropdown
  5. Choose the sort order in the second dropdown: Is Off First or Is On First
  6. Click Save

Show or hide elements based on a switch field

You can use conditionals with a CMS switch field to show or hide elements in a Collection list or on a Collection page.

For example, you can use a switch field to:

  • Show a label only for certain items (e.g., show a “Featured” label only when a “Featured” switch is On)

  • Show or hide an entire section for certain items (e.g., show a contact form section only when a “Show contact form” switch is On)

To show or hide an element based on a switch field:

  1. Select the element to show or hide (must be inside a Collection list or on a Collection page)

  2. Go to Element settings > Visibility

  3. Click the “plus” icon

  4. Choose your switch field

  5. Set the rule to Is > On / Off

  6. Set Visibility > Visible or Hidden

  7. Set Else > Visibility > Visible or Hidden

  8. Click off the modal or press Esc on your keyboard to save the conditional