The name of the cookie to set. May be a reference variable
cookie_valuerequiredstring
attributesoptionaldictionary
Key:value pairs with unique keys. May use the variable arguments syntax. Additional directives to use when setting the cookie
Options
expiresoptionalvalue
Expiration date/time
pathoptionalvalue
Cookie path
domainoptionalvalue
Cookie domain
secureoptionalvalue
True to set the secure flag on the cookie
httponlyoptionalvalue
True to set the httponly flag on the cookie
There are a small number of reserved and forbidden cookie names, the most prominent being "_mp_permissions" - the name of the cookie used by Marketpath for handling permissions. You must use the {% set_client_permission %} and {% unset_client_permission %} methods to manage permissions instead of manipulating the permissions cookie directly.
Checks if the "allow_public_statistics" custom permission has been set, and if it has gathers information about the current session statistics for storage in a "site_statistics" cookie - presumably for display using javascript on the site.
{% unset_cookie %}
"Unsets" one or more cookies. Because of how cookies work, this will actually ADD the cookie to the response with an expiration date in the past.
{% unset_cookie names %}Parameters
namesrequiredlist
One or more values. May use the variable arguments syntax. The names of the cookies to unset
If the "advertising_id" cookie has been set and the "allow_advertising" permission has NOT been granted, use the unset_cookie method to clear both the "advertising_id" and "advertising_alt_id" cookies.
Unset multiple Cookies
Liquid
{%- var unset_cookies = request.query_params.unsetcookies | split: ',' -%}
{%- for cookie in unset_cookies -%}
{%- var cookie_alt = cookie | append:'-alt' -%}
{%- unset_cookie &cookie &cookie_alt -%}
{%- endfor -%}
Checks if the "unsetcookies" query parameter was included in the request, and for each comma-delimited cookie name to unset, unset both the specified cookie and the "-alt" version of the cookie if it exists by using the unset_cookie method with two reference variables.
{% 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 %}Parameters
propertiesrequireddictionary
Key:value pairs with unique keys. May use the variable arguments syntax.
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
Liquid
{%- 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".
{% unset_session %}
Removes custom properties from the session.
{% unset_session properties? %}Parameters
propertiesoptionallist
One or more values. May use the variable arguments syntax. The names of the properties to remove. If not included, all properties will be removed
ExampleHow to use the unset_session method
Simple Use Case
Liquid
{%- if client_permissions.do_not_track -%}
{%- unset_session -%}
{%- endif -%}
If the browser sent the "Do Not Track" header, remove all session properties.
Checks if the "ad_setting=false" query parameter was sent with the request, and if it was, explicitly deny the "ads" client permission and unset the three specified session properties. Multiple properties can be unset at once by providing each property name as a separate argument to the unset_session method.
Unset Session Properties Dynamically
Liquid
{%- var props = request.query_params.clearprops | split: ',' -%}
{%- for prop in props -%}
{%- unset_session &prop -%}
{%- endfor -%}
Checks if the "clearprops" query parameter was included in the request, and if it was, unset the specified session properties using the reference variable syntax.
Checks if the "clearprops" query parameter was included in the request, and if it was, converts the comma-delimited list of property names to a space-delimited list and unsets the session properties with those names using the expanded variable syntax.
{% 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_client properties %}Parameters
propertiesrequireddictionary
Key:value pairs with unique keys. May use the variable arguments syntax.
ExampleHow to use the set_client method to store custom data on the client
This example uses the set_client method to save multiple dynamic values on the client for later use. The submittedForms variable is incremented by 1, the lastKnownEmail variable is set to the submission email, and a dynamic variable constructed from the name of the form prepended by 'submitted' will also be set to 'true'.
{% unset_client %}
Removes custom properties from the client.
{% unset_client properties? %}Parameters
propertiesoptionallist
One or more values. May use the variable arguments syntax. The names of the properties to remove. If not included, all properties will be removed
ExampleHow to use the unset_client method to clear client properties
Unsets the specified client properties if the "reset_counters" query parameter is present.
Unset Client Properties Dynamically
Liquid
{%- var props = request.query_params.clearprops | split: ',' -%}
{%- for prop in props -%}
{%- unset_client &prop -%}
{%- endfor -%}
Checks if the "clearprops" query parameter was included in the request, and if it was, unset the specified client properties using the reference variable syntax.
Checks if the "clearprops" query parameter was included in the request, and if it was, converts the comma-delimited list of property names to a space-delimited list and unsets the client properties with those names using the expanded variable syntax.
ExampleUnset the client when Do Not Track is presentWhen the Do Not Track header is present, unset the client so no client-specific data is stored.
Liquid
{%- if client_permissions.do_not_track -%}
{%- unset_client -%}
{%- endif -%}
{% 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.
{% set_profile attributes %}Parameters
attributesrequireddictionary
Key:value pairs with unique keys. May use the variable arguments syntax.
ExampleSet the current user's profileAssociate the current user with a profile using set_profile so profile-specific content and settings apply.
Liquid
{%- if submission.is_valid -%}
{%- var bestScoreName = form.name.value | classname | prepend:'bestscore-' -%}
{%- var bestScore = submission.score | to_int -%}
{%- var previousBestScore = profile.attributes[bestScoreName] | to_int -%}
{%- if previousBestScore > bestScore -%}
{%- set bestScore = previousBestScore -%}
{%- endif -%}
{%- set_profile last_score:submission.score &bestScoreName:bestScore -%}
{%- endif -%}
{% 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.
{% unset_profile attributes %}Parameters
attributesrequiredlist
One or more values. May use the variable arguments syntax.
There is no option to unset all attributes from a profile - attributes must be removed by name.
ExampleClear the current profile with unset_profileClear the current profile with unset_profile so the user is no longer associated with that profile.
Checks if the "clearprops" query parameter was included in the request, and if it was, converts the comma-delimited list of property names to a space-delimited list and unsets the profile properties with those names using the expanded variable syntax.
Unset Multiple Profile Properties
Liquid
{%- if submission.is_valid and submission.score.value < 80 -%}
{%- unset_profile passed_certification_exam user_is_certified_for_x -%}
{%- endif -%}
Unset multiple profile properties at the same time. In this example, the template will unset the "passed_certification_exam" and "user_is_certified_for_x" properties if the submission is valid and the score is less than 80.
{% 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 %}Parameters
var, set, or assignoptionalkeyword
Optional. Specify either "var", "set" or "assign" to change which scope this {% set_profile_setting %} is stored on. "var" is the default behavior.
variableoptionalvariable
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.
propertiesrequireddictionary
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
ExampleHow to use the set_profile_setting methodSaves 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.
Simple Use Case
Liquid
{%- 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
Liquid
{%- 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.
{% 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.
{% unset_profile_setting [[var, set, or assign]? errors=variable]? properties %}Parameters
var, set, or assignoptionalkeyword
Optional. Specify either "var", "set" or "assign" to change which scope this {% unset_profile_setting %} is stored on. "var" is the default behavior.
variableoptionalvariable
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.
propertiesrequiredlist
One or more values. May use the variable arguments syntax. The ids of the settings to remove from the profile
There is no option to unset all settings on a profile - settings must be unset by name.
ExampleUnset a profile settingRemove a profile setting value with unset_profile_setting so it is no longer stored for the current profile.
Unsets the "description" profile setting if the "clear_description" post parameter is present.
Unset Multiple Profile Settings at Once
Liquid
{%- if submission.is_valid and submission.score.value < 80 -%}
{%- unset_profile_setting passed_certification_exam certification_category -%}
{%- endif -%}
Unset multiple profile settings at the same time. In this example, the template will unset the "passed_certification_exam" and "certification_category" settings if the submission is valid and the score is less than 80.
Unset Profile Settings Dynamically with Validation
Liquid
{%- var clearsettings = request.post_params.clearsettings | split: ',' | join:' ' -%}
{%- var profile_errors = null -%}
{%- if clearsettings is_valid -%}
{%- unset_profile_setting set errors = profile_errors *clearsettings -%}
{%- if profile_errors -%}
{%- for error in profile_errors -%}
<p class="error">Error clearing <strong>{{error.Key}}</strong>: {{error.Value}}</p>
{%- endfor -%}
{%- endif -%}
{%- endif -%}
Checks if the "clearsettings" post parameter was included in the request, and if it was, converts the comma-delimited list of setting names to a space-delimited list and unsets the profile settings with those names using the expanded variable syntax. If any of the settings are invalid, the errors are saved to the "profile_errors" variable and displayed to the user.
{% 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.
Must be one of allow, deny, 1 (alias for allow), or 0 (alias for deny). Defaults to allow
permission_namerequiredstring
The name of the permission to allow or deny. Defaults to the session permission
renewoptionalliteral
If this permission has already been allowed or denied, the original permission expiration date will only be updated if "renew" is specified
valueoptionalstring
The value to store along with the specified permission
alwaysoptionalbool
Specifies that the permission should not expire, which is a shortcut for a 50-year expiration date
foroptionalliteral
Specify in combination with the duration. If specified, the always and until clauses are not allowed
durationoptionalstring
How long until the permission should expire, specified as "num [minutes|hours|days|weeks|months|years]" where num is a positive integer. May either be specified directly in the method or read from a variable
untiloptionalliteral
Specify in combination with the date. If specified, the always and for clauses are not allowed
dateoptionaldate
The date that the permission will expire. If it is in the past, the permission will automatically be denied as expired
If none of the expiration clauses are specified, the permission expiration date will default to 1 year in the future. Remember that the expiration date specified here is for the permission, not for the effects of the permission. In the case of sessions, the expiration date defines how long the user has granted permission to have a session, regardless of the number or duration of sessions during that timeframe. If the permission has a value, the value will be stored along with the permission regardless of whether the permission has been allowed or denied. Permissions will never expire in the middle of a session - if a permission would be set to expire in the middle of a session, it will automatically be extended until the end of the session to prevent odd mid-session permission change bugs.
ExampleHow to use the set_client_permission method to allow or deny permissionsAllow or deny client permissions (e.g. session, ads) and set expiration or store values.
Liquid
{%- if request.query_params.allow_session == "true" -%}
{%- var allow_length = "1 year" -%}
{%- if request.query_params.allow_months -%}
{%- set allow_length = request.query_params.allow_months | append: " months" -%}
{%- endif -%}
{%- set_client_permission allow session renew for allow_length -%}
{%- elsif request.query_params.deny_session == "true" -%}
{%- set_client_permission deny renew -%}
--equivalent to {% set_client_permission deny session renew for 1 year -%}
{%- endif -%}
Allow the session permission for the default timeframe (1 year). If the session has already been allowed, the renew argument will cause it to be updated with the new timeframe. Equivalent to {% set_client_permission allow session renew for 1 year %}
If the "allowed_ids" query parameter was passed in the request, store it's value in the allowed partner_ids permission. If the "denied_ids" query parameter was passed in the request, store it's value in the denied denied_ids permission. For both of these permissions, the expiration date will use the default timeframe (1 year) if the permission was not previously specified, and will remain unchanged if the permission was previously specified.
Dynamically Set the Length of a Permission
Liquid
{%- if request.query_params.allow_session == "true" -%}
{%- var allow_length = "1 year" -%}
{%- if request.query_params.allow_months is_int true and request.query_params.allow_months > 0 -%}
{%- set allow_length = request.query_params.allow_months | append: " months" -%}
{%- endif -%}
{%- set_client_permission allow session renew for allow_length -%}
{%- elsif request.query_params.deny_session == "true" -%}
{%- set_client_permission deny renew -%}
{%- endif -%}
If the "allow_session" query parameter is set to true, sets or renews the session permission. The session permission is allowed for a default of 1 year, but if the "allow_months" query parmeter is a positive number then it will be used to set the length of the session permission. If the "deny_session" query parameter is set to true, updates the session permission to be denied for the default timeframe (1 year).
If event.end_date is a valid date, set a permission with the name of the event to allow until the specified date. The permission will expire at event.end_date.
Set Permissions Dynamically
Liquid
{%- if request.query_params.allow_networks -%}
{%- var networks = request.query_params.allow_networks | split: ',' -%}
{%- for network in networks -%}
{%- if network is_valid -%}
{%- set_client_permission allow network -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
If the "allow_networks" query parameter was passed in the request, set a permission for each network in the list. This works because "network" is a variable containin a string. If it were not a variable on the current scope, then the permission would be named "network" instead.
This code will sometimes work by setting a permission with the name "partner_ids", but if there is also a variable with that name then the value of the variable will be used instead, resulting in unexpected behavior. This can be easily avoided by placing the permission name in single or double quotes.
ExampleHow to use the unset_client_permission method
Simple Use Case
Liquid
{%- if request.query_params.user_confirmation != permissions.external_user.value -%}
{%- unset_client_permission external_user -%}
<p>Some error message about failed confirmation and please try again</p>
{%- endif -%}
If the "user_confirmation" query parameter is not equal to the value of the "external_user" permission, unset the "external_user" permission and display an error message.
Unset Permissions Dynamically
Liquid
{%- var unset_parties = request.query_params.third_party_unknowns | split: ',' -%}
{%- for party in unset_parties -%}
{%- unset_client_permission party -%}
{%- endfor -%}
Loop through a dynamic list of permissions and unset each one.
Unset Permissions Dynamically Using the Expanded Variable Syntax
If the "unset_permissions" query parameter was included in the request, convert the comma-delimited list of permission names to a space-delimited list and unset the permissions with those names using the expanded variable syntax.
Check whether all permissions should be unset or only most by safely unsetting all but the specified values. If not all permission should be unset, then store the values of permissions that should be preserved in separate variables, unset all permissions, and restore the permissions that should be preserved.
ExampleHow to use the unset_session method
Simple Use Case
Liquid
{%- if client_permissions.do_not_track -%}
{%- unset_session -%}
{%- endif -%}
If the browser sent the "Do Not Track" header, remove all session properties.
Checks if the "ad_setting=false" query parameter was sent with the request, and if it was, explicitly deny the "ads" client permission and unset the three specified session properties. Multiple properties can be unset at once by providing each property name as a separate argument to the unset_session method.
Unset Session Properties Dynamically
Liquid
{%- var props = request.query_params.clearprops | split: ',' -%}
{%- for prop in props -%}
{%- unset_session &prop -%}
{%- endfor -%}
Checks if the "clearprops" query parameter was included in the request, and if it was, unset the specified session properties using the reference variable syntax.
Checks if the "clearprops" query parameter was included in the request, and if it was, converts the comma-delimited list of property names to a space-delimited list and unsets the session properties with those names using the expanded variable syntax.
{% unset_client_permission %}
Removes the specified permissions from the permissions cookie. Note that this is not the same as denying permission since there will be no record that permission was either granted or denied after the permission has been unset.
One or more values. May use the variable arguments syntax. The names of the permissions to remove. If not included, all permissions will be removed
ExampleHow to use the unset_client_permission method
Simple Use Case
Liquid
{%- if request.query_params.user_confirmation != permissions.external_user.value -%}
{%- unset_client_permission external_user -%}
<p>Some error message about failed confirmation and please try again</p>
{%- endif -%}
If the "user_confirmation" query parameter is not equal to the value of the "external_user" permission, unset the "external_user" permission and display an error message.
Unset Permissions Dynamically
Liquid
{%- var unset_parties = request.query_params.third_party_unknowns | split: ',' -%}
{%- for party in unset_parties -%}
{%- unset_client_permission party -%}
{%- endfor -%}
Loop through a dynamic list of permissions and unset each one.
Unset Permissions Dynamically Using the Expanded Variable Syntax
If the "unset_permissions" query parameter was included in the request, convert the comma-delimited list of permission names to a space-delimited list and unset the permissions with those names using the expanded variable syntax.
Check whether all permissions should be unset or only most by safely unsetting all but the specified values. If not all permission should be unset, then store the values of permissions that should be preserved in separate variables, unset all permissions, and restore the permissions that should be preserved.