Set_profile_setting

Set_profile_setting

{% 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_profile_setting [[var, set, or assign]? errors=variable]? properties %}

{% set_profile_setting
var, set, or assign
 
Optional. Specify either "var", "set" or "assign" to change which scope this set_profile_setting is stored on. "var" is the default behavior.
errors=
variable
 
The variable to save validation errors to. Validation errors will be specified as a list of Key:Value pairs, or null if there are no validation errors.
properties
 
Key:value pairs with unique keys. May use the variable arguments syntax. The settings to set on the profile. Each property key should match a setting id, and the property value will be used for the setting value
%}

Related

{% set_title %}

Sets the page title.

{% auth set_setting %}

Sets the specified profile settings to their new values on the auth profile (which is not necessarily the same as the currently-logged in profile). If any of the specified settings has validation, the new settings will be validated before being set. An invalid value for any setting will prevent any of the new settings from being set. If the profile exists and the auth is not aborted before the end of the request the new values will be saved to the profile. If the auth is aborted then the new values will not be saved in between requests. If the profile does not exist but is registered in the same request then the new values will be saved on the new profile.

{% 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_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.

{% auth unset_setting %}

Unsets the specified profile settings from the auth profile (which is not necessarily the same as the currently-logged in profile). For settings with default values this will set them back to their defaults. For settings without default values this will set them to empty/unselected/false. If any of the specified settings is required, it will result in an invalid_value error and will prevent any of the new settings from being unset. If the auth is aborted then the unset settings will not be saved in between requests.

{% profile %}

{% 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.

{% unset_profile %}

Removes custom properties from the attribute dictionary of the currently logged-in profile. Note that this is meaningless unless the user is logged in.

{% 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 }}.

{{ profile }}

{% unset_profile_setting %}

Removes custom values from the profile settings for the currently logged-in profile. Note that this is meaningless unless the user is logged in. For settings with a default value this will reset them to the default, and for all other settings this will set them to empty/unselected/false. Profile settings may be required and include validation, in which case all settings will be validated before being removed and any validation error will prevent any settings 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 }}.

Examples

Saves custom values to predefined profile settings that will be accessible whenever the current profile 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.

How to use the set_profile_setting method

Copy

Simple Use Case

{% if submission.is_valid and submission.score > 70 %}
{% set_profile_setting passed_test:'true' %}
{% endif %}
Stores a value in the "passed_test" profile setting. Does not check if the user is currently logged in, verify that the "passed_test" setting is valid, or check for other errors. If the user is not logged in or the setting is not valid, it simply won't be saved.

Use Case with Validation

{% var new_layout = request.post_params['layout'] %}
{% var new_companyname = request.post_params['companyname'] %}
{% var new_description = request.post_params['description'] %}
{% set_profile_setting var errors = profile_errors layout:new_layout companyname:new_companyname description:new_description %}
{% if profile_errors %}
{% for error in profile_errors %}
<p class="error">Error saving <strong>{{error.Key}}</strong>: {{error.Value}}</p>
{% endfor %}
{% endif %}
Stores the values of the "layout", "companyname", and "description" form fields in the profile settings. If any of the settings are invalid, the errors are saved to the "profile_errors" variable and displayed to the user.