Expressions for LWR Sites

Overview

With expressions, you can make calculations and access property values and other data to pass into the component’s attributes. Use expressions for dynamic output or for passing values into components by assigning them to attributes.

An expression is any set of literal values, variables, subexpressions, or operators that can be resolved to a single value. Method calls aren’t allowed in expressions.

The expression syntax is: {!expression} where expression is a placeholder.

Data Binding Expressions

ExpressionDescriptionSupported Pages and Components

{!Item.field}

Gets the data for the field on the current bound data.

Anything that’s bound to data. Can include Salesforce CMS or record data.

{!Item.field._rawValue}

Gets the raw value for the data field.

Anything that’s bound to CRM data.

{!Item.field._displayValue}

Gets the formatted and localized value for the data field.

Anything that’s bound to CRM data.

{!Item._detailURL}

Gets the URL of a Salesforce CMS data item.

Anything that’s bound to a CMS item, including CMS detail pages.

{!Label.namespace.name}

Defines the label’s localized value when you specify labels in Experience Builder.

First, create a translated custom label in Salesforce Setup. For more information, see Translate Custom Labels. Then, use the label expression in any Experience Builder component that has a text field to see the localized label.

Other Expressions

Use other expressions to query parameters, resolve the correct basePath for a site, or leverage user fields in expressions.

ExpressionDescriptionSupported Pages and Components

{!Route.param}

Gets a query parameter from the URL.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!param}

Gets a parameter value from a URL where : precedes the parameter. For example, gets {!term} from the /global-search/:term URL.

  • All pages with a dynamic parameter in their URL

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!Site.basePath}

Resolves to the basePath of the LWR site.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!User.userId}

Resolves to the Salesforce ID of the user.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!User.isGuest}

Returns TRUE or FALSE based on whether the user is a guest user.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!User.Record.<User sObject Field>}

Resolves to the value of a Salesforce User Object’s field.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

{!User.Commerce.BuyerGroups}

Returns a list of buyer groups associated with the user when used in sites that are built using the Commerce templates.

  • All pages

  • Out-of-the-box and custom components with string properties

  • HTML Editor

  • Rich Content Editor

  • When you use the {!param} or {!Route.param} expression in the HTML Editor or Rich Content Editor components, some HTML special characters are escaped, or replaced with different values, for security purposes. These characters include <, >, and &.

  • LWR sites don’t support expressions that display authenticated user information, starting with {!CurrentUser.

  • Expressions with user data are resolved for Rich Content Editor only on Preview and Published sites.

  • When binding User data, you can access all the User sObject fields using the {!User.Record.<User sObject Field>} expression. You can also use the {!User.Commerce.<Commerce Field>} expression to access user data related to Commerce in sites built using the Commerce templates. In the Summer ’23 release, only BuyerGroups is supported as a Commerce field.

Source

https://developer.salesforce.com/docs/atlas.en-us.exp_cloud_lwr.meta/exp_cloud_lwr/advanced_expressions.htm

Last updated