Use a prefix to set the data source context

Most SitecoreAI components are designed for reusability and pull data from data source items. This means that the content they display is not bound to the page on which they appear but is stored in data source items. A component data source is the item that you set on a component to define where the content is pulled from for that component.

SitecoreAI provides several ways to assign a data source to a component. You can run a source field report to set the data source context, but you can also use prefixes to determine the data source context.

Pull the data source from a field

To pull the component data source from a field:

  • Use the following prefix:

    Prefix

    field:<field name>

    Example

    field:Title

If you use a field name from a context item as the data source, SitecoreAI does the following:

  • If the field type is a link field, then SitecoreAI uses the target item ID as a data source.

  • If the field type is not a link field, and the field value is not empty, then SitecoreAI uses the field raw value as a data source.

This can be convenient when, for example, you have a product detail page that uses a partial design and you want a component in the partial design to pick the content from the product item field itself.

Specify a data source relative to the page

Instead of specifying the full path of the item, you can use a special notation to make that path relative to the context item. SitecoreAI converts the relative path to a full item path when the page is rendered.

This can be convenient for reusable page elements, for example, in partial designs when you want to store the data underneath each page rather than taking it from a global location.

To specify the data source relative to the page, use the page and local prefixes:

Prefix

page:<relativepath>

local:<relativepath>

Example

page:/blog1

local:/data/text1

For items with dashes, use hashtags. For example:

page:/#my-test-blog#

SitecoreAI uses the page: notation for components stored underneath a page in the page data folder. In many cases, the page: and local: notation give you the same result. When used in partial designs, the local: notation results in items taken from under that partial design whereas the page: forces SitecoreAI to always look for the data source under the page.

Do you have some feedback for us?

If you have suggestions for improving this article,