Measurable Success «10 Checkpoints for Future-Proof Enterprise CMS» White Paper
Measurable Success - White Paper
New in 1.18.0

Obj.onSite(siteId)

Returns a SiteContext for the site specified by its ID.

const frenchSiteContext = Scrivito.Obj.onSite('Bordeaux');
const wineBlog = frenchSiteContext.where('_objClass', 'equals', 'Blog').take(1);

Returns a SiteContext for accessing CMS objects belonging to a different site than the current one. Note that Scrivito.Obj only returns objects part of the current site.

Returns

SiteContext – a SiteContext

Examples

onSite can also be invoked on a custom class. The returned site context will additionally restrict returned Obj instances to those belonging to the class, similar to Scrivito.Obj (i.e. for get, all and where).

const News = Scrivito.getClass('News');
const frenchNews = News.onSite('fr');
const mostRecentFrenchNews = frenchNews.all().orderBy('published_at').take(1);

If an Obj is created using this site context, it belongs to the site of the site context.

const ProductPage = Scrivito.getClass('ProductPage');
const bikePages = ProductPage.onSite('bikes');
const newBikePage = bikePages.create({ batteryCapacity: '20 TWh' });

console.log('SiteId:', newBikePage.siteId()); // => SiteId: bikes