Build an Expression-Based Visibility Rule in LWR Sites Using Custom Logic

Build your own custom logic to show or hide a component or component variation. Create a custom logic expression by adding your conditions for component visibility.

Required Editions

Available in: Salesforce Classic and Lightning Experience
Available in: Enterprise, Performance, Unlimited, and Developer Editions
Applies to: LWR sites
User Permissions Needed
To create an Experience Cloud site: Create and Set Up Experiences AND View Setup and Configuration
To customize or publish an Experience Cloud site:
  • Create and Set Up Experiences AND View Setup and Configuration AND be a member of the site

    OR

  • View Setup and Configuration AND be a member of the site AND have appropriate role-based site access

You can create visibility rules for any component in Experience Builder from the Visibility tab. Before creating a custom logic expression, add and specify the conditions. When you add a condition, it’s numbered. Your first condition is numbered 1, the second is numbered 2, and so forth. Use these conditions to build your expression.

  1. From Experience Builder, select a component that appears on the canvas.
  2. From the Visibility tab, click + Add Visibility Rule.
  3. From the Component State dropdown, choose to show or hide the component.
  4. To add a condition for the logic, click Add Condition. Choose values for all the conditions that you add.
    Add at least two conditions.
  5. From the When dropdown, select The Custom Logic Is Met.
  6. In the Custom Logic field, enter your custom logic expression.
    Consider these criteria when you build a custom logic expression: Include at least 2 conditions, use all the added conditions, and use only AND and OR operators.
  7. Save your work.
Example
Example

Consider a scenario where you add three conditions: 1, 2, and 3. Your custom logic expression can be 1 AND 2 OR 3. In this case, your component or variation would appear when the conditions 1 and 2 are met, or when only condition 3 is met.

Another scenario: Consider the logic ((1 OR 2) AND (2 OR 3)). In this example your component would appear when either condition 1 or 2 is met AND condition 2 or 3 is met.