The embedded items and objects in the Scriban context

Version: 10.4

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 item

Type

Value

i_home

Sitecore.Data.Items.Item

Home page item of the site for which the rendering process is performed.

i_datasource

Sitecore.Data.Items.Item

The item that was specified as the data source for the component.

i_item

Sitecore.Data.Items.Item

The 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_site

Sitecore.Data.Items.Item

The root item of your site. In most cases, this item is the parent of your home page.

i_page

Sitecore.Data.Items.Item

The 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 object

Type

Value

o_language

Language

The language of the current page.

o_model

Object

The model that is passed to your MVC Controller rendering

o_geospatial

Sitecore.XA.Foundation.Search.Models.Geospatial

Location information for the currently rendered item with geospatial properties.

o_context

Sitecore.XA.Foundation.Abstractions.IContext

Context information for the currently rendered page.

o_pagemode

Sitecore.XA.Foundation.Abstractions.IPageMode

Context 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 name

Type

Usage

poi_type_id

Sitecore.Data.ID

Guid of the POI type.

poi_icon

String

POI icon URL.

latitude

Double

Latitude of the POI that is rendered.

longitude

Double

Longitude of the POI that is rendered.

distance

Double – nullable

Returns the distance between the POI and the location of the client provided to the search service.

unit

Double - nullable

Kilometers, 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 name

Type

Usage

is_administrator

Bool

Indicates whether the current user is an administrator.

user

User

User in whose context the request is performed.

domain

Sitecore.Security.Domains.Domain

Domain of the user in whose context the request is performed.

database

Sitecore.Data.Database

Database 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 name

Type

Usage

is_debugging

bool

Indicates that the page is rendered in debug mode.

is_experience_editor

bool

Indicates that the page is rendered within Experience Editor.

is_experience_editor_editing

bool

Indicates that the page is rendered within Experience Editor in Edit mode.

is_normal

bool

Indicates that the page is rendered for a visitor.

is_preview

Indicates that the page is rendered within Experience Editor in Preview mode.

is_simulated_device_previewing

Indicates that the page is rendered within Experience Editor in Simulated Preview mode.

is_profiling

Indicates that the page is rendered with profiling information.

Example:

RequestResponse
{{ if (o_pagemode.is_experience_editor_editing) }}
  <span>[Click here to edit the component]</span>
{{ else }}
  ... render the component here
{{ end }} 

Do you have some feedback for us?

If you have suggestions for improving this article,