1. Scriban templates

The embedded items and objects in the Scriban context

Version:

SXA embeds several objects into the Scriban rendering context. You can use these objects like any regular Scriban variable. This topic describes the default embedded items and objects.

Note

The available embedded objects should cover most functionality for rendering component HTML and content. If you require more functionality, SXA comes with two pipelines that allow you to inject additional objects into the Scriban context, and extend the item property list.

Embedded items

Because Sitecore stores content within items, SXA embeds several content items within the Scriban runtime. You can use those items to access the content of their fields or traverse the item structure by retrieving their children or parent.

Embedded itemTypeValue
i_homeSitecore.Data.Items.ItemHome page item of the site for which the rendering process is performed.
i_datasourceSitecore.Data.Items.ItemThe item that was specified as the data source for the component.
i_itemSitecore.Data.Items.ItemThe current item within the rendering variant context. Often, this is an equivalent to the i_datasource.

If your Scriban template was embedded within a Query or Reference rendering variant field, i_item will be exactly the item that other rendering variant fields would use for their rendering process.
i_siteSitecore.Data.Items.ItemThe root item of your site. In most cases, this item is the parent of your home page.
i_pageSitecore.Data.Items.ItemThe item that represents the page that is currently rendered.

Context objects

Context objects let you perform more complex logic. For example, rendering different content based on the circumstances in which the page is viewed, rendering additional data for your editors but hiding it for visitors, or rendering different texts depending on the language of the page.

The context objects are listed in the following table and described in more detail after the table:

Context objectTypeValue
o_languageLanguageThe language of the current page.
o_modelObjectThe model that is passed to your MVC Controller rendering
o_geospatialSitecore.XA.Foundation.Search.Models.GeospatialLocation information for the currently rendered item with geospatial properties.
o_contextSitecore.XA.Foundation.Abstractions.IContextContext information for the currently rendered page.
o_pagemodeSitecore.XA.Foundation.Abstractions.IPageModeContext information for the currently rendered page.

o_language

The language of the current page.

o_model

The MVC model object. This object differs depending on which component it is used for. Based on the business logic required to be rendered, you must align with your back-end developer to provide the precalculated values.

o_geospatial

Location information for the currently rendered item with geospatial properties.

Note

This object is only accessible when performing a geospatial search within the Search Results rendering.

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

Property nameTypeUsage
poi_type_idSitecore.Data.IDGuid of the POI type.
poi_iconStringPOI icon URL.
latitudeDoubleLatitude of the POI that is rendered.
longitudeDoubleLongitude of the POI that is rendered.
distanceDouble – nullableReturns the distance between the POI and the location of the client provided to the search service.
unitDouble - nullableKilometers, miles.

o_context

The context object contains information about the request for which the component is rendered. You can include page mode, language, and other useful information that you might want to render parts of your template conditionally.

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

Property nameTypeUsage
is_administratorBoolIndicates whether the current user is an administrator.
userUserUser in whose context the request is performed.
domainSitecore.Security.Domains.DomainDomain of the user in whose context the request is performed.
databaseSitecore.Data.DatabaseDatabase from which the request sources the data.

o_pagemode

The pagemode object is part of the o_context object that was extracted to shorten the notation of code that needs to render conditionally based on which mode the page is rendered in.

The following table lists notable properties of the o_pagemode context object:

Property nameTypeUsage
is_debuggingboolIndicates that the page is rendered in debug mode.
is_experience_editorboolIndicates that the page is rendered within Experience Editor.
is_experience_editor_editingboolIndicates that the page is rendered within Experience Editor in Edit mode.
is_normalboolIndicates that the page is rendered for a visitor.
is_previewIndicates that the page is rendered within Experience Editor in Preview mode.
is_simulated_device_previewingIndicates that the page is rendered within Experience Editor in Simulated Preview mode.
is_profilingIndicates that the page is rendered with profiling information.

Example:

{{ if (o_pagemode.is_experience_editor_editing) }}
  <span>[Click here to edit the component]</span>
{{ else }}
  ... render the component here
{{ end }}
If you have suggestions for improving this article, let us know!