Building a Purple Experience
views.json

Global Data

6min

Purple Experience



Global

The Global view, when available in your Experience set-up, is automatically loaded within the Experience. It loads all globally defined data sources from this view. These data sources are accessible from any view using the $global identifier.

Field

Description

globalData

Specify the complete set of global data sources that need to be accessible across all views.

Global data may not be accessible when in offline mode. Keep in mind, a basic version of your app should also work when not being connected to the internet. For more information, see Offline behaviour.

When global data is configured, it is globally available in your Purple Experience and loaded in every view. Global data is only loaded once and only on the server side, so any Information, i.e. holding data about purchases or the customer himself cannot be used here.

There are three types of global data available to the Purple Experience: 

  • Global Data configured in the Purple Hub
  • Global Data created from data on the Content Cloud
  • Global Data set in the Purple Experience Builder

These global data sources are very powerful, so use them with care. Adding a lot of data here has the potential to make initial requests for your content VERY slow. Also, the total amount of data loaded can affect the performance and therefore the Lighthouse and SEO score of your page.

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.

Global Data configured in the Purple Hub

For setting up Global Data configured in the Purple Hub go to

Purple Hub > Settings > Cloud Settings.

Those settings consists of anything the editorial team should be able to configure in the Purple Experience. The parameters are defined through Advanced Custom Fields (ACFs), so please seek the advice of your respective project manager at Purple upon the setup. The content of those fields is published as usual, to the Purple Content Cloud.

The settings are published to the Purple Content Cloud and loaded within every view rendering.

The data is available from the global context using this key $global.appSettings.options_ACFGroupNAME.ACFNAME

No further configuration in the Purple Experience is required to access this data.

Global Data created from data on the Content Cloud

In the Purple Experience Builder, within the Purple Experience View, which is not technically a view, you can configure an entity in views.json that provides data to your app in any view. Any data source configured here will be available to any of your views. Specify a key so that you can easily access it through the global context.

Purple Experience View


To access global data use $global.experienceConfig.your_data_source_key.

Global Data set in the Purple Experience Builder

Within the experience.config.json, you may specify any configuration that you want to make available to any view in your app. The content of this config may be any valid JSON.

To access any of the data from this example experience.config.json: { "your_setting": { "your_sub_setting": 3 } } use $global.experienceConfig.your_setting.your_sub_setting.