AppData

To access configuration, use require('appData')in a server side script context.

Using AppData for HTML input elements

// 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');

Using AppData for SiteVision components

// 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');
...
// 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');

AppData for the SiteVision metadata selector

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, '');

SiteVision node types

Refer to the node types documentation to see what properties are available for different node types. Values retrieved from appData.get() are JavaScript compatible.

  • PropertyType.DATE returns a timestamp
  • PropertyType.WEAKREFERENCE returns an ID