Conditional visibility

 

Conditional visibility is the most versatile way to show or hide elements in a dynamic design, allowing you to create unique designs for different Collection items based on different criteria. Unlike filters, which specify which Collection items are visible in a Collection List, conditions specify when any element (static or dynamic) is visible in a Collection List or a Collection Page.

This lesson covers:

  • Setting conditional visibility
  • Condition rules
  • Conditions vs filters
  • Example 1: Show/hide an element in a Collection List
  • Example 2: Show/hide a label
  • Example 3: Highlight the current item
  • Example 4: Show/hide a section on a Collection Page

Setting conditional visibility

By setting conditional visibility, you’re specifying when an element is visible. The condition is based on what value a field, or an item, has in the Collection List item or Collection page you’re on. Each Collection field type has different conditions you can choose from. Follow these steps to set a condition:

  1. Select an element, static or dynamic, inside a Collection List or Collection Page that you want to only show when a specific condition is met
  2. Go to the Settings panel (D)
  3. In the Conditional visibility section, add a Condition by clicking the plus (+) button
  4. In the first dropdown, select the field you want the visibility to be based on
  5. Choose the condition in the second dropdown
  6. Specify a value if needed
  7. Click Save

You can add as many conditions as you want. When multiple conditions are applied, it means all conditions must be met for it to be visible. You can also delete conditions by clicking the trash can icon next to the condition.

Condition rules

Condition rules, like filter rules, are either field-based or item-based.

Field-based conditions

Field-based conditions take effect when a given field:

  • Is set or is not set
  • Equals or doesn’t equal a certain value
  • Is greater than, less than, or is a number between two numeric values
  • Is ON or OFF
  • Belongs to a certain date range

Item-based conditions

Item based conditions apply when a collection item is or is not the current item.

Conditions vs filters

While Collection List filters allow you to show or hide Collection items in a Collection List based on a rule, conditional visibility uses the same rules to show or hide elements within Collection Lists or on Collection Pages.

For example, you can use the rule “Featured (switch) is on” to show a “Featured” text label for featured blog posts and hide this label for elements that have the featured switch set to off. On the other hand, if you wish to only show featured posts in a list, you can set this same rule as a filter on the Collection List.

Example 1: show/hide an element in a Collection List

Let’s say you have a Collection List containing team members. Some of them have an email address, but others don’t. And in your Collection List, you have a text link that gets the URL from the email field. But, as we mentioned above, some team members don't have email addresses listed. So, we need to hide the text link for those who don’t have an email link. To do that:

Type image caption here (optional)
  1. Select the text link
  2. Add a Condition stating that the element is visible when an email address field is set
  3. Click Save
 

Example 2: show/hide a label

Say you have a Collection List of blog posts, and you want to show a “Featured” label for featured items. Since any element added in a Collection List appears in all Collection items, you can use conditional visibility to hide this element for items that do not meet the condition: “Featured is on.”

  1. Create a “Featured” label in your blog posts Collection List
  2. Select the label
  3. Add a Condition stating that the element is visible when Featured? (switch) is on
  4. Click Save

Example 3: Highlight the current item

Let’s say you have a list of blog posts on a blog post Collection page. This list also includes the blog post item for the current blog post, the page you are currently on. You can hide this current blog post using filters, or, you can highlight it by creating a second design for the Collection items. Now, you will have 2 representations for each blog post in each Collection item in your Collection List.

Since you want to show the unique design only for the current blog post, you need to do 2 things:

  1. Add a condition to hide the first design — “Post item wrapper” in this example — for the current item
  2. Add a condition to show the new design — “Current post item wrapper” in this example — only for the current item

Example 4: show/hide a section on a Collection Page

You may have a section that you only want to show on certain Collection Pages. You can create a condition that this section and all its children are only visible, for example, when the category is “Christmas.”

  1. Select the section
  2. Add a Condition
  3. Select the Category field in the first dropdown
  4. Choose equals in the second dropdown
  5. Specify Christmas as value
  6. Save