Id

Id

{% id %}

Creates a "unique" identifier each time it is called. Each identifier consists only of lowercase letters, and each subsequent call simply increments it by 1 character (ie: 'aaa' -> 'aab' -> 'aac', etc...). Identifiers created using this method are not random and therefore will not prevent caching. However, if the number of times the id method is called or if the arguments to the id method is changed the identifiers may not be consistent between page loads - which means that you should not rely on identifiers created using this method for styling or for creating sharable links.

{% id output_to_template? [[var, set, or assign]? variable]? output_to_template? [= attributes ]? %}

{% id
output_to_template
 
If included the id will be output directly to the template.
var, set, or assign
 
Optional. Specify either "var", "set" or "assign" to change which scope this id is stored on. "var" is the default behavior.
variable
output_to_template
 
If included the id will be output directly to the template.
=
attributes
 
Key:value pairs with unique keys. May use the variable arguments syntax.
%}

attributes

prefix
 
String to prepend before the id
suffix
 
String to append after the id
length
 
The desired string length of the id, excluding the prefix and suffix
skip
 
Use this to skip past a specific id. Useful in edge-cases where you need to avoid identifiers before a specific value

Related

{% gallery %}

{% articles %}

{% auth change_id %}

Functions as an alternate init command if the old_id argument is supplied. Sets the id for the profile to the id specified. If ths site is configured to set the id an email to the same value then this will validate the id as a valid email address and will set the email to this value as well. Note that this does NOT log the profile out, deactivate it, or require any further confirmation or action by the user to continue using their profile. Those actions are up to the template developer to execute (which we strongly recommend whenever the email address is changed). Sets {{ auth.id_changed }} to true if successful or false if not. If successful sets {{ auth.old_id }} and {{ auth.new_id }} to the old and new id values and sets {{ auth.id }} to the new id. Note that any future auth init commands will have to use the new id instead of the old one. If successful and the site is configured to set the id and email to the same value then this also sets {{ auth.email_changed }} to true and sets {{ auth.old_email }} and {{ auth.new_email }} to the old and new email values. If successful, the {% auth abort %} command may not be called.

{% auth change_id old_id? new_id %}

{% auth
change_id
old_id
 
The id of the profile to change
new_id
 
The new id for the profile May use liquid filters.
%}

Error Codes:
command_disabled - Indicates that the current method has been disabled at the site level. This will be set for any auth method if profiles are disabled.
duplicate_command - Indicates that the {% auth change_id %} method has already been called. It may only be called once per page load. If the site is configured to set the id and email to the same value then this error code may also indicate that the {% auth change_email %} method has already been called.
no_init - Indicates that no initialization method has been called yet and no value was provided to the old_id parameter.
bad_init - Indicates that another initialization function was called with a different id.
aborted - Indicates that the method could not be performed because {% auth abort %} has been called.
not_found - Indicates that no profile was found with the old id.
blocked - Indicates that the profile is currently blocked.
locked - Indicates that the profile is currently locked.
inactive - Indicates that the profile is currently inactive and must be activated first.
missing_value - Indicates that no new_id argument was supplied to the {% auth change_id %} method.
unchanged - Indicates that the id was not changed because it was the same as the old id.
duplicate_value - Indicates that another profile already exists with the new id.
unexpected - Indicates that the system encountered an unexpected error which is not due to any of the common issues associated with profiles. This is a rare error code but may be possible in edge cases such as duplicate concurrent requests, infrastructure issues, or suspected security incidents.

Related

{% articles %}

{% auth change_email %}

Functions as an alternate init command if the id argument is supplied. Sets the email for the profile to the email specified. Will also set the id to this value if the site is configured to set the id and email to the same value. Note that this does NOT log the profile out, deactivate it, or require any further confirmation or action by the user to continue using their profile. Those actions are up to the template developer to execute (which we strongly recommend whenever the email address is changed). Sets {{ auth.email_changed }} to true if successful or false if not. If successful sets {{ auth.old_email }} and {{ auth.new_email }} to the old and new email values. If successful and the site is configured to set the id and email to the same value this will also set {{ auth.id_changed }} to true, {{ auth.old_id }} and {{ auth.new_id }} to the old and new id values, and {{ auth.id }} to the new id. Note that in this case any future auth functions will be required to use the new id. If successful, the {% auth abort %} command may not be called.

Examples

Demonstrates multiple ways to use the id method to generate semi-unique ids.

Generate Id

Copy

Simple Use Case

<form id="{% id %}">
Every time the id method is used, it will generate a new semi-unique identifier. The id method will never produce the same identifier multiple times in the same pageload. If the generated identifier is not saved in a variable, it will be output directly to the template.

Long Id

<div id="{% id = length:32 suffix:'_longidentifier' %}">
The length option specifies the length of the id to generate - in this example 32 characters. The maximum allowed value for the length parameter is 36 characters. The suffix option appends the specified string to the end of the id.

Short Id

<div id="{% id = length:1 prefix:'myid_' %}">
The length option specifies the length of the id to generate - in this example 1 character. The prefix option prepends the specified string before the generated id.

Skip Id

<div id="{% id = skip:'ffffffff' suffix:'_images' %}">
{% for image in entity.images %}
<div id="{% id var image_id output_to_template = length:8 prefix:'img_' %}">...</div>
{% endfor %}
</div>
The skip option specifies the id to skip past - in this example 'ffffffff'. Note that for the following ids to continue past the skipped id, the length parameter must be set to the correct value. The skip option is mostly useful when you need to generate unique ids for partial html content to be loaded using javascript.

Save Id

<form id="{% id var form_id output_to_template = prefix:'myform_' %}">...</form>
<script type="text/javascript">var myform = document.getElementById('{{form_id}}'); ...</script>
It is often useful to save the generated id to a variable so that it can be used in later template code, such as in javascript initialization code. This may also be combined with the output_to_template option to output the id to the template as well as store it in the specified variable.