The session data object

The session data object contains a single property from the user session. The user session can be used to store generic string data, but not objects. The data is structured as properties that can each have values being strings, hash maps (of other session data object properties) or arrays.


[property name]

Returns the session data object associated with a specified property name. If a new property name is used, the session data object is created.

Syntax:

[property name] → session data object

Returns:

The session data value associated to a specified property name.

Example:

Here are some examples of how to obtain session data values:

<#assign pref = session.preferences>
<#assign lang = session.preferences.lang>
<#assign theme = session.preferences.theme>
<#assign themeName = session.preferences.theme["name"]>

add

Adds a data value to this session property. If several values are added to a property, all the values can be retrieved by handling the property as an array.

Syntax:

add(value) → nothing

Example:

The following code adds several values for the session property "test" and then prints all the values:

${liquidsite.session.test.add("one"}
${liquidsite.session.test.add("two"}
<#list liquidsite.session.test as value>
  Value: ${value}
</#list>

remove

Removes a session property value. This method can also be used to remove individual values in a list of property values by first indexing the values.

Syntax:

remove() → nothing

Example:

This following code removes the first value for the session property "test":

${liquidsite.session.test[0].remove(}