Test Enterprise-Class Web CMS Scrivito Free for 30 Days
Test Scrivito Free for 30 Days

SiteContext

SiteContext

A SiteContext provides access to CMS objects, taking their respective website assignment into account. It can be used to retrieve, search and create CMS objects (see below).

Background

In a multi-site-enabled Scrivito application, every CMS object has a siteId. A site is the collection of all CMS objects that have the same siteId.

A multi-site Scrivito application is executed in the context of a specific site, derived from its current browser location. Scrivito.Obj can be considered the SiteContext of the current site, meaning that Scrivito.Obj limits access to CMS objects to this current site.

SiteContext types

Actually, there are two types of SiteContext, each one with a specific site restriction:

The single-site context

Scrivito.Obj.onSite returns the single-site context for the site specified by the siteId passed to it. Also, Scrivito.Obj represents the single-site context of the current site.

The context restricts access to CMS objects belonging to the site specified by the siteId or, respectively, the current siteId. Its methods return exclusively Obj instances of this site.

On creation of a CMS object (create, createFromFile), it gets assigned to the site of the context.

The all-site context

This special site context provides access to any Obj instance, regardless of its site, as opposed to the above-mentioned current site context Scrivito.Obj.

Note that this is the only site context that can be used in siteIdForUrl to dynamically identify the ID of the current site based on the site’s base URL.

Instance method summary

  • New in 1.18.0

    Returns an ObjSearch of all CMS objects assigned to the site context.

  • New in 1.18.0

    Creates a new Obj with the given attributes and assigns it to the site.

  • New in 1.18.0

    Creates a binary Obj by uploading a file. The created obj is assigned to the site context.

  • New in 1.18.0

    Retrieves the Obj specified by its id, if it is part of the site context.

  • New in 1.18.0

    Fetches the Obj with the given path from the site context.

  • New in 1.18.0

    Fetches the Obj with the given permalink from the site context.

  • New in 1.18.0

    Returns the Obj whose _path is "/" if it is part of the site context.

  • New in 1.18.0

    Returns an ObjSearch with the given initial subquery based on the specified arguments. The search returns only CMS objects that are part of the site context.