To access configuration, use require('appData')
in a server side script context.
Global appData is configuration that is shared among all instances of a WebApp. Configuration of global appData takes place in the addon-view of the Sitevision editor (found in the app's context menu when a config/global/index.html file is present).
To access global configuration, use require('globalAppData')
in a server side script context.
The globalAppData-object and the regular appData-object share all features.
// index.html
<div class="form-group">
<label>Text</label>
<input class="form-control amazing-class" name="theTextField">
</div>
// index.js
var appData = require('appData');
...
// returns the text value from the input field
text = appData.get('theTextField');
// index.html
<div class="form-group">
<label>Page</label>
<input class="form-control" data-component="page-selector" name="page">
</div>
<div class="form-group">
<label>Pages</label>
<input type="hidden" data-component="page-list" name="pages">
</div>
// index.js
var appData = require('appData'),
globalAppData = require('globalAppData');
...
// returns the JCR Node
page = appData.getNode('page');
// returns the JCR Node identifier i.e: '4.540818ed12a6539aa3f80001645'
pageId = appData.get('page');
/*
* returns an object with given properties of the JCR Node i.e:
*
* {
* URI: '/4.540818ed12a6539aa3f80001645.html',
* displayName: 'Home',
* published: true,
* publishDate: 1227618333142
* }
*/
pageData = appData.get('page', 'URI', 'displayName', 'published', 'publishDate');
/* getArray [@since 4.5.3]
*
* returns value as an array
* - an array of JCR Nodes for list components
* - value wrapped in an array for single type components
*/
pages = appData.getArray('pages');
The metadata selector manages a metadata definition. Though, in many cases the metadata value is of interest.
Tip! The metadata value for a specific node can be resolved using the name of the metadata definition.
// index.html
<div class="form-group">
<select class="form-control" data-component="metadata-selector" name="metadef"></select>
</div>
// index.js
var appData = require('appData'),
portletContextUtil = require('PortletContextUtil'),
propertyUtil = require('PropertyUtil'),
...
// Get the metadata definition JCR Node
metadataDefinition = appData.getNode('metadef');
// Get the name of the metadata definition and the Node of interest
nameOfTheMetadata = metadataDefinition.getName();
currentPage = portletContextUtil.getCurrentPage();
// ...and resolve the metadata value
metadataValue = propertyUtil.getString(currentPage, nameOfTheMetadata, '');
Refer to the node types documentation to see what properties are available for different node types. Values retrieved from appData.get()
are JavaScript compatible.