1. Renderings (Scriban)

The embedded Commerce items and objects for Scriban templates

Version:

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.


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 objectTypeValue
o_storefrontcontextSitecore.Commerce.XA.Foundation.Common. Context.IStorefrontContextThe properties and configurations that give access to the properties, configurations, and settings of the current storefront.
o_sitecontextSitecore.Commerce.XA.Foundation.Common. Context.ISiteContextThe 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:

PropertyTypeUsage
ContextSitecore.Commerce.XA.Foundation.Common. Context. IContextProvides an  interface to access HttpContext properties.
CurrentStorefrontSitecore.Commerce.XA.Foundation. Common.Models. CommerceStorefrontEstablishes the current storefront site.
IsStorefrontApiCallResponseContextbooleanIndicates whether the current context is an AJAX call request.
IsStorefrontSitebooleanIndicates 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:

PropertyTypeUsage
ContextSitecore.Commerce.XA.Foundation.Common. Context. IContextProvides an  interface to access HttpContext properties.
CurrentCatalogItemSitecore.Data.Items.ItemGet access to the currently selected catalog item even when wildcard approach is in use.
CurrentItemSitecore.Data.Items.ItemGets or sets the current context item. With direct navigation, it is the same as CurrentCatalogItem.
IsCategorybooleanGets a value indicating whether the instance of the CurrentCatalogItem is a category.
IsProductbooleanGets a value indicating whether the instance of the CurrentCatalogItem is product.
ItemsSystem.Collections.IDictionaryProvides access to the collection of Http request  cached items.
UrlContainsCategorybooleanEstablishes whether the current Url contains the category.
VirtualFolderstringGets site virtual folder
If you have suggestions for improving this article, let us know!