Storing Data
The userData object manages data associated with the currently authenticated portal user. If no user is currently logged in, stored data is associated with, and expires with, the current user session. The siteData object manages data associated with the portal itself, and is not associated with any particular user.
These objects are available on every page, and provide simple methods for storing
and
retrieving virtually any data structure in a persistent way. For example, you can
store a
value using put(key, value)
on one page, and on another page, retrieve the
value with get(key)
.
The siteData object provides additional methods for storing and searching arbitrary data structures in user-defined search indexes. It also provides methods to add, retrieve, and delete files in a project that is associated with the portal.
For a full description of how userData and
siteData
work, see and . This functionality can also be leveraged using client-side
Javascript; see .
Here is a more complex example:
<!-- The view will be of the 'current' state; next view will show new state. --> <#assign counter = userData.get('counter')!0/> ${userData.put('counter', counter + 1)} <p>Counter value: ${counter}</p> <!-- Store the 5 most recent counters --> <#assign counterList = userData.getList('counterList')![]/> <p>Counter list: ${counterList?join(', ')?html}</p> ${userData.push('counterList', counter, 5)} <!-- You can also store complex objects and arrays --> ${userData.put('object', {"a": 5, "b": "foo"})} ${userData.put('array', [1, 2, 3, 4, 5])} ${userData.push('complexData', {"I": "am", "a": {"nested": "structure"}});
The built-in theme's Recently Viewed Documents, Recent Searches, and Favorites features are implemented using userData.