The session object

The session object represents an http session.


clear

Clears all data in the user session.

Syntax:

clear()

Example:

The following code clears all data in the user session:

${liquidsite.session.clear()}

create

Creates a new user session if one didn't already exist.

Syntax:

create()

Example:

The following code creates a new user session:

${liquidsite.session.create()}

destroy

Destroys the user session.

Syntax:

destroy()

Example:

The following code destroys the user session:

${liquidsite.session.destroy()}

exists

Checks if a user session exists. If a new session was created as a result of processing the request, this flag will still be false.

Syntax:

exists → boolean

Example:

The following code checks if a user session exists:

<#if liquidsite.session.exists>
    Session exists.
<#else>
    Session does not exist.
</#if>

[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 = liquidsite.session.preferences>
<#assign lang = liquidsite.session.preferences.lang>
<#assign theme = liquidsite.session.preferences.theme>
<#assign themeName = liquidsite.session.preferences.theme["name"]>