Set_session

Set_session

{% set_session %}

Saves custom properties on the session. Note that this doesn't mean much unless the user (or the developer) has granted permission for sessions.

{% set_session properties %}

{% set_session
properties
 
Key:value pairs with unique keys. May use the variable arguments syntax.
%}

Related

{% set_title %}

Sets the page title.

{% unset_session %}

Removes custom properties from the session.

{% set_description %}

Sets the meta description for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

{% set_timezone %}

Sets the default timezone to use when rendering dates and times on the page that do not already have a separate timezone configured.

{% set_content_type %}

Sets the Content-Type header for the HTTP response.

{% set_robots %}

Sets the robots meta directive.

{% set_client %}

Saves custom properties on the client that will survive across multiple sessions until they are changed, unset, or the "session" permission expires. Note that this doesn't mean much unless the user (or the developer) has granted permission for sessions.

{% set_favicon %}

Sets the URL to the favicon for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

{% set_profile_setting %}

Saves custom values to predefined profile settings that will be accessible whenever the current profile is logged in. Note that this is meaningless unless the user is logged in. Profile settings may include validation, in which case all settings will be validated before being set and any validation error will prevent the setting(s) from being set. Validation errors may optionally be output to a variable.

{% set %}

Replaces a value on the nearest scope where it has already been defined. If it has not been defined yet, it is stored on the root scope.

{% set_header %}

Sets one or more headers in the HTTP response.

{% set_client_permission %}

Defines whether the client has granted or deined permission for a particular feature (eg: sessions). The only permission defined by default is the session permission (configurable in the site properties). However, the template developer may use this mechanism for their own purposes as well. The permissions defined by this method will be stored in the permissions cookie, which may be read and/or modified by client-side javascript.

{% set_dictionary %}

Sets properties on an editable dictionary object. If the dictionary does not exist it will be created and stored on the current scope. If the dictionary exists but is not editable this will throw an error.

{% set_cookie %}

Sets a cookie in the HTTP response.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

{% set_response_code %}

Sets the HTTP response status code.

{{ session }}

The session object is available on every page, and contains information about the user's current session. Note that most of these properties are only meaningful if the user has allowed permission for sessions. Additionally, sessions require cookies in order to work. Requests made without cookies (such as by bots or browsers with cookies disabled) or without permission for sessions will always behave like an initial page-load without existing session information. The session object is one of a handful of simple mechanisms to enable personalization on your site. Used well, these can be powerful tools for developers and website owners.

{% set_profile %}

Saves custom properties on the profile that will be accessible whenever the current profile is logged in. The properties will be saved to the profile's attribute dictionary. Note that this is meaningless unless the user is logged in.

Examples

How to use the set_session method

Copy

Simple Use Case

{% if request.query_params.sortby %}
{% set_session sortby:request.query_params.sortby %}
{% endif %}
{% var sortby = session.sortby | default: 'post_date' %}
{% blog_post_collection posts sort_by:sortby %}
This example uses the set_session method to save the "sortby" query parameter, so that future visits to the same page will utilize the same sorting even if it does not include the sortby parameter.

Advanced Use Case

{% if submission.is_valid and submission.object_type = 'form_submission' %}
{% var forms_submitted = session.submittedForms | to_int | plus: 1 %}
{% var session_formname = form.name.value | prepend:'submitted_' %}
{% set_session formSubmitted:"true" submittedForms:forms_submitted domain:submission.domain &session_formname:'true' %}
{% endif %}
If submission is a valid form submission object, this examples saves four session variables for later use: formSubmitted will be set to "true", submittedForms will be incremented by 1, domain will be set to the submission domain, and a dynamic session variable constructed from the name of the form prepended by "submitted" will also be set to "true".