Context Data
9 min
the context object $context provides information like data results for the views you can use it to get the content fields of the context object inside the views json example usage $context issue (deprecated) accesses a data source of type issue $context platform possible values web, android, ios $context subscription it's filled when subscription data source is used $context content accesses data for a content $context preview the value from the url, e g https //www example com/somearticle html?preview=true, only available in web $context preview app the preview app metadata key https //gitlab sprylab com/purple/purple javascript api/ /blob/master/purpleinterface js?ref type=heads#l3063 states the same value as context preview, but in app $context userattributes you may set and access data related to the user here it's persisted in local storage intro $global global application data (e g , menus, configs, and taxonomies) have a separate scope for being accessed the "global" scope is implemented as an object on the window level, so it will get reloaded when reloading the page configure "global" for your application within the views json within global, you may specify data sources that store their data under the "contextkey" in a global scope object additionally, a storedata object containing key value pairs may be given, which stores the evaluated values (replacestring) under the key in the global scope object the global section is executed only once at "app start" within ssr if the global scope does not exist yet we do not perform any change detection in all evaluations besides $context and $functions, there is also $global available to access that global store note when evaluating any value in a field (whether static or dynamic), all falsy values—such as undefined, null, false, 'undefined', 'null', and 'false'—will be returned as null body tag attributes body tag attributes are pieces of information that are added to your website's main html\<body> element these attributes represent the experience view context body attributes appear in your website's html like this \<body data storefront platform="web" data pxp device os="web" data pxp preview app="false"> \<! experience website content > \</body> this attributes start with a prefix (like data storefront or data pxp ) contain key value pairs of information are visible in the browser's developer tools can be accessed by scripts and styling what changed in experience 5 0 0 now, only specific, essential information appears on your website's html body tag platform information (always visible) data pxp platform identifies what type of platform your website is running on (web, mobile, etc ) app id (development/testing only) data pxp app id is visible when preview=true custom attributes additional information you specifically choose to display, configured in the experience config json example `` how to configure custom attributes 1 access experience configuration file 2 add the attributes add a bodyattributes section in purple context updates what triggers a context update trigger changed key(s) when it happens url query param changes query param keys + resolved objects (publication, issue, category, search result, …) on every navigation or manual url change data source finishes loading the data source’s contextkey after each api response entitlement / metadata refresh all metadata keys (entitlement token, today, connection state, …) after login/logout or explicit updatemetadata() entitlement state change (all components) broadcasts an empty {} change — forces full re evaluation user attributes change userattributes when setuserattribute() is called account data update accountdata after login or updateaccountdata() network status change connection state when device goes online/offline what the context object contains the $context object is built by merging several layers later layers override earlier ones when keys overlap layer order fixed fields initialurl pathurl userattributes accountdata outlet metadata entitlement token today connection state other platform metadata url query params all parameters from the current url view context resolved objects such as publication issue category search result parent list / swiper item injected when a component is a direct child of a list or swiper parent list injection (layer 5 explained) each list item injects its data into the child component’s context key behavior default key = data source type example content → $context content can be overridden with { "entryid" "customkey" } additional fields $context entryindex → item position $context groupindex → group position (if grouped lists)