PageContext class

The SharePoint page context object.

Remarks

The page context provides standard definitions for common SharePoint objects that need to be shared between the client-side application, web parts, and other components. Typically the data is fetched via REST queries when navigating to a new page, but it can also be preloaded by the web server, or filled from a custom application cache.

Constructors

(constructor)(serviceScope)

Constructs a new instance of the PageContext class

Properties

aadInfo

Contextual information for communicating with Azure Active Directory. If the current page doesn't have an associated Azure Active Directory tenant, this property will be undefined.

cultureInfo

It provides culture info for the current user of the application. This class is primarily used with the PageContext class.

isInitialized

Returns whether the PageContext has been initialized.

legacyPageContext

An object providing classic SharePoint properties that may be required by certain legacy scripts.

list

Contextual information for the SharePoint list that is hosting the page. If there is no list associated to the current page, this property will be undefined.

listItem

Contextual information for the SharePoint list item that is hosting the page. If there is no list item associated to the current page, this property will be undefined.

serviceKey

The service key for PageContext.

site

Contextual information for the SharePoint site collection ("SPSite") that is hosting the page.

user

It provides contextual information for the SharePoint user that is accessing the page. This class is primarily used with the PageContext class.

web

Contextual information for the SharePoint site ("SPWeb") that is hosting the page.

Constructor Details

(constructor)(serviceScope)

Constructs a new instance of the PageContext class

constructor(serviceScope: ServiceScope);

Parameters

serviceScope
ServiceScope

Property Details

aadInfo

Contextual information for communicating with Azure Active Directory. If the current page doesn't have an associated Azure Active Directory tenant, this property will be undefined.

get aadInfo(): AzureActiveDirectoryInfo | undefined;

Property Value

@microsoft/sp-page-context!AzureActiveDirectoryInfo:class | undefined

cultureInfo

It provides culture info for the current user of the application. This class is primarily used with the PageContext class.

get cultureInfo(): CultureInfo;

Property Value

isInitialized

Returns whether the PageContext has been initialized.

get isInitialized(): boolean;

Property Value

boolean

legacyPageContext

An object providing classic SharePoint properties that may be required by certain legacy scripts.

get legacyPageContext(): any;

Property Value

any

Remarks

This property is provided to facilitate migration of legacy code. It returns a JavaScript object whose contents are similar to the _spPageContextInfo window variable from classic pages. The contents of this variable may change in future releases of SharePoint. For this reason, new projects are encouraged to use the SharePoint Framework TypeScript APIs instead, since they are fully documented and provide reliable backwards compatibility guarantees.

NOTE: If certain functionality is exposed in the legacyPageContext but does not seem to have a proper TypeScript API, please file an issue on GitHub. The intention is that no modern application should need to rely on the legacyPageContext object.

list

Contextual information for the SharePoint list that is hosting the page. If there is no list associated to the current page, this property will be undefined.

get list(): SPList | undefined;

Property Value

SPList | undefined

listItem

Contextual information for the SharePoint list item that is hosting the page. If there is no list item associated to the current page, this property will be undefined.

get listItem(): SPListItem | undefined;

Property Value

SPListItem | undefined

serviceKey

The service key for PageContext.

static readonly serviceKey: ServiceKey<PageContext>;

Property Value

site

Contextual information for the SharePoint site collection ("SPSite") that is hosting the page.

get site(): SPSite;

Property Value

user

It provides contextual information for the SharePoint user that is accessing the page. This class is primarily used with the PageContext class.

get user(): SPUser;

Property Value

web

Contextual information for the SharePoint site ("SPWeb") that is hosting the page.

get web(): SPWeb;

Property Value