Dictionary
{{ dictionary }}
Object containing a list of key-value pairs where the keys are unique.
Properties of {{ dictionary }} objects
| Name |
Type |
Description |
| is_valid |
Boolean |
True if there is at least one key-value pair |
| value |
String |
The json representation of the values. For dictionary fields you do not typically care about this - use values instead |
| editable |
Boolean |
True if properties can be added or removed from this dictionary. This will only be true if the dictionary was created using the {% create_dictionary %} method |
| keys |
list |
A list of strings containing all of the keys in the dictionary |
| values |
object |
An object containing all of the keys and values of the dictionary |
| count |
Integer |
The number of key-value pairs in the dictionary |
| field_id |
String |
The identifier for this field |
| label |
String |
The label for this field |
| output |
String |
The JSON representation of the values. May include additional markup in the editor preview to make it easier to edit content |
Individual dictionary values may be accessed using the {{ dictionary.keyName }}, {{ dictionary["keyName"] }}, {{ dictionary.values.keyName }}, or dictionary.values["keyName"] syntax. You may also treat this object as a list containing all of the keys which may be iterated using a {% for %} loop.
Related
May be any object, including simple, complex and list objects. In some cases may even include symbols and null.
Can be any text, from the empty string ("") to the full HTML output of the template. When used alone in a conditional, all strings evaluates as true - even if they are empty or a value such as "0" or "false".
Can be any number, including integers, decimals, or the value 0. Any value - including 0 - evaluates as true when used alone in a conditional.
The site object is available on every page, and contains information about the current site. This information is the same on every page for the site.
A whole (non-fractional, non-decimal) number. May be 0. Any value - including 0 - evaluates as true when used alone in a conditional.
An enumerable list containing zero or more objects. Lists may contain many different object types, although most lists only contain a single object type. There are a large number of other complex object types that are also lists (ag: an articlelist is a complex object but is also a list of article objects).
{% create_dictionary %}
Creates a new editable dictionary with the given properties.
Examples
Demonstrates how to create Settings Dictionary.
{% capture settings %}
inputs: posts
number: 5
style: 'two-tone'
sortable: false
original_entity: entity
{% endcapture %}
{% create_dictionary settings = *settings %}
{{ settings | inspect }}
Related
Object containing a list of key-value pairs where the keys are unique.
Removes properties from an editable dictionary object. If the dictionary does not exist an empty one will be created and stored on the current scope. If the dictionary exists but is not editable this will throw an error.
Copies properties from one or more copyable objects (eg: dictionaries) into an editable dictionary. If the dictionary is not editable this will throw an error. If the dictionary does not exist then one will be created and saved on the current scope.
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_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.
Examples
Demonstrates how to set Dictionary Properties.
{% var inputname = 'inputs' %}
{% set_dictionary settings = &inputname:posts number:posts.size sortable:true %}
Related
Object containing a list of key-value pairs where the keys are unique.
Removes properties from an editable dictionary object. If the dictionary does not exist an empty one will be created and stored on the current scope. If the dictionary exists but is not editable this will throw an error.
Sets the meta description for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.
Saves custom properties on the session. Note that this doesn't mean much unless the user (or the developer) has granted permission for sessions.
Sets the default timezone to use when rendering dates and times on the page that do not already have a separate timezone configured.
Sets the Content-Type header for the HTTP response.
Sets the robots meta directive.
Copies properties from one or more copyable objects (eg: dictionaries) into an editable dictionary. If the dictionary is not editable this will throw an error. If the dictionary does not exist then one will be created and saved on the current scope.
Creates a new editable dictionary with the given properties.
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.
Sets the URL to the favicon for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.
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.
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.
Sets one or more headers in the HTTP response.
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.
Sets a cookie in the HTTP response.
Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.
Sets the HTTP response status code.
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.
{% unset_dictionary %}
Removes properties from an editable dictionary object. If the dictionary does not exist an empty one will be created and stored on the current scope. If the dictionary exists but is not editable this will throw an error.
Examples
Demonstrates how to unset Dictionary Properties.
{% capture unset_properties %}
{{inputname}}
number
sortable
{% endcapture %}
{% unset_dictionary settings *unset_properties style %}
Related
Object containing a list of key-value pairs where the keys are unique.
Removes custom properties from the session.
Removes custom properties from the client.
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.
Removes custom properties from the attribute dictionary of the currently logged-in profile. Note that this is meaningless unless the user is logged in.
Copies properties from one or more copyable objects (eg: dictionaries) into an editable dictionary. If the dictionary is not editable this will throw an error. If the dictionary does not exist then one will be created and saved on the current scope.
Creates a new editable dictionary with the given properties.
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.
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.
"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.
{% copy_to_dictionary %}
Copies properties from one or more copyable objects (eg: dictionaries) into an editable dictionary. If the dictionary is not editable this will throw an error. If the dictionary does not exist then one will be created and saved on the current scope.
The following objects are copyable and can be used as arguments in the {% copy_to_dictionary %} method:
dictionary - will copy all of the dictionary properties from one dictionary to another
labels - will copy all of the key-value pairs from the labels field to the dictionary. If the labels field contains duplicate keys then only one of the values will be copied for that key.
profile - will copy all of the profile settings to the new dictionary
datastore_item - will copy all of the datastore fields to the new dictionary, along with the datastore item name (as a text object), title (as a text object), and folder (as a folder object) if it is in a folder
form_submit - will copy all of the form submission values (as their respective object types) to the new dictionary
client - will copy all of the client properties as strings to the new dictionary
cookies - will copy all of the cookies as strings to the new dictionary
request.headers - will copy all of the request headers as strings to the new dictionary
client_permissions - will copy all of the permissions (as permission objects) that have been specified for the client to the new dictionary - including both allowed and denied permissions
post_params - will copy all of the post parameters from the request to the new dictionary. Parameter values will either be strings or arrays (if the request had multiple post parameters with the same name).
query_params - will copy all of the query parameters (as strings) from the request to the new dictionary.
session - will copy all of the session properties as strings to the new dictionary
site - will copy all of the settings (as their respective object types) from the site to the new dictionary
Examples
Demonstrates how to copy Dictionary.
{% create_dictionary pagination = limit:5 page:2 %}
{% create_dictionary sorting = sort_by:"post_date" sort_direction: "desc" %}
{% comment %}This will create a new dictionary if it does not already exist. Any previous filters may be overwritten from request.post_params.{% endcomment %}
{% copy_to_dictionary filters = request.post_params pagination sorting %}
{% comment %}If you use the new_only instruction then previous filters will not be overwritten.{% endcomment %}
{% create_dictionary filters = blog:entity.blog_main tag:entity.tag_filter %}
{% copy_to_dictionary filters = pagination sorting request.post_params new_only %}
Related
Object containing a list of key-value pairs where the keys are unique.
Removes properties from an editable dictionary object. If the dictionary does not exist an empty one will be created and stored on the current scope. If the dictionary exists but is not editable this will throw an error.
Creates a new editable dictionary with the given properties.
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.
Examples
Demonstrates how to create Settings Dictionary.
{% capture settings %}
inputs: posts
number: 5
style: 'two-tone'
sortable: false
original_entity: entity
{% endcapture %}
{% create_dictionary settings = *settings %}
{{ settings | inspect }}
Demonstrates how to unset Dictionary Properties.
{% capture unset_properties %}
{{inputname}}
number
sortable
{% endcapture %}
{% unset_dictionary settings *unset_properties style %}
Demonstrates how to set Dictionary Properties.
{% var inputname = 'inputs' %}
{% set_dictionary settings = &inputname:posts number:posts.size sortable:true %}
Demonstrates how to list all keys and values for a dictionary field.
<ul>
{% for key in entity.dictionary_field %} --equivalent to {% for key in entity.dictionary_field.keys %}
<li><strong>{{key}}</strong> = {{entity.dictionary_field.values[key]}}</li>
{% endfor %}
</ul>
Demonstrates how to reference a dictionary field property in multiple ways.
{% if entity.dictionary_field.custom_key_1 is_valid %}
<p>Custom Key 1: {{entity.dictionary_field.custom_key_1}}</p>
{% endif %}
{% if entity.dictionary_field['custom_key_2'] is_valid %}
<p>Custom Key 2: {{entity.dictionary_field['custom_key_2']}}</p>
{% endif %}
{% if entity.dictionary_field.values.custom_key_3 is_valid %}
<p>Custom Key 3: {{entity.dictionary_field.values.custom_key_3}}</p>
{% endif %}
{% if entity.dictionary_field.values['custom_key_4'] is_valid %}
<p>Custom Key 4: {{entity.dictionary_field.values['custom_key_4']}}</p>
{% endif %}
<ul>
{% for field in entity.dictionary_field.keys %}
<li><strong>{{ field }}</strong> = {{ entity.dictionary_field.values[field] }}</li>
{% endfor %}
</ul>
Output an unordered list containing all of the dictionary field properties and their values by enumerating the keys property.
<ul>
{% for field in entity.dictionary_field %}
<li><strong>{{ field }}</strong> = {{ entity.dictionary_field[field] }}</li>
{% endfor %}
</ul>
Directly enumerating the dictionary object is the same as enumerating the keys property, so this example is functionally identical to the previous example.
Demonstrates how to copy Dictionary.
{% create_dictionary pagination = limit:5 page:2 %}
{% create_dictionary sorting = sort_by:"post_date" sort_direction: "desc" %}
{% comment %}This will create a new dictionary if it does not already exist. Any previous filters may be overwritten from request.post_params.{% endcomment %}
{% copy_to_dictionary filters = request.post_params pagination sorting %}
{% comment %}If you use the new_only instruction then previous filters will not be overwritten.{% endcomment %}
{% create_dictionary filters = blog:entity.blog_main tag:entity.tag_filter %}
{% copy_to_dictionary filters = pagination sorting request.post_params new_only %}