The embedded Commerce items and objects for Scriban templates

Current version: 10.2

You can use embedded functions and embedded objects and items to customize your SXA Storefront Scriban templates.

The Commerce Foundation layer injects embedded objects into the Scriban rendering context that you can use like any regular Scriban variable. These embedded objects are particularly useful when you are using canonical URLs and provide access to the properties of StorefrontContext and SiteContext as shown in the following diagram.

Class diagram for the iStorefront and ISiteContext.

You access these objects from the Scriban template using the following code.

RequestResponse
o_storefrontcontext.is_storefront_site
o_sitecontext.current_catalog_item

SXA Storefront supports wildcard navigation, which is used when dealing with canonical URLs for catalog items. As an abstraction, you can use o_sitecontext.current_catalog_item when you want to access the current catalog item and it resolves the catalog item no matter if wildcard or direct navigation is used in the URL. You can also quickly determine if the current item is a catalog item – category or product – or a regular page item.

Embedded items

Sitecore stores content within items and embeds content items within the Scriban runtime. You can use these items to access the content of their fields or traverse the item structure by retrieving their children or parent. See The embedded items and objects in the Scriban context.

Context objects

You can implement complex logic using context objects. This is useful when rendering:

  • different content based on the circumstances in which the page is viewed.

  • additional data for your editors but hiding it for visitors to your storefront site.

  • different text depending on the language of the page.

The following table lists the context objects available.

Context object

Type

Value

o_storefrontcontext

Sitecore.Commerce.XA.Foundation.Common. Context.IStorefrontContext

The properties and configurations that give access to the properties, configurations, and settings of the current storefront.

o_sitecontext

Sitecore.Commerce.XA.Foundation.Common. Context.ISiteContext

The current catalog item and related properties. It also contains the current HTTP context.

o_storefrontcontext

The o_storefrontcontext object determines the storefront context and contains information about the request that the component is rendered for.

The following table lists the properties for the o_storefrontcontext context object:

Property

Type

Usage

Context

Sitecore.Commerce.XA.Foundation.Common. Context. IContext

Provides an  interface to access HttpContext properties.

CurrentStorefront

Sitecore.Commerce.XA.Foundation. Common.Models. CommerceStorefront

Establishes the current storefront site.

IsStorefrontApiCallResponseContext

boolean

Indicates whether the current context is an AJAX call request.

IsStorefrontSite

boolean

Indicates whether the current site is a storefront site.

o_sitecontext

The o_sitecontext object provides access to site and page specific properties and determines the current storefront site and resolves the catalog item as well as the HTTP context.

The following table lists notable properties for the o_sitecontext context object:

Property

Type

Usage

Context

Sitecore.Commerce.XA.Foundation.Common. Context. IContext

Provides an  interface to access HttpContext properties.

CurrentCatalogItem

Sitecore.Data.Items.Item

Get access to the currently selected catalog item even when wildcard approach is in use.

CurrentItem

Sitecore.Data.Items.Item

Gets or sets the current context item. With direct navigation, it is the same as CurrentCatalogItem.

IsCategory

boolean

Gets a value indicating whether the instance of the CurrentCatalogItem is a category.

IsProduct

boolean

Gets a value indicating whether the instance of the CurrentCatalogItem is product.

Items

System.Collections.IDictionary

Provides access to the collection of Http request  cached items.

UrlContainsCategory

boolean

Establishes whether the current Url contains the category.

VirtualFolder

string

Gets site virtual folder

Do you have some feedback for us?

If you have suggestions for improving this article,