get_user_field_values
A Smarty function to retrieve user field values for a given field
The get_user_field_values
function is used to retrieve User Field values for the current user in an efficient manner.
Where more than one value exists for a given field, they will be returned from newest to oldest.
Accepted Parameters
Parameter | Value | Description | Required |
---|---|---|---|
field | 'my_field' | The name of the user field. This will return an empty array if the field does not exist within Aurora, or if the current user does not have any values set for that field. | Yes |
item | 'my_variable' | The name of the template variable to assign the result to. If not set the result will be returned. | No |
Example Template Code
Returning the result
{get_user_field_values field='my_field'}
Using this method signature will return the values to the template. Since the result will always be an array, and Smarty will always cast it to a string, this will always result in the text "Array" being rendered in the template. It only makes sense to use the function in this way in combination with a modifier such as array_first_value. This would make sense when the User Field is intended to hold only a single value. For example:
<p>Hello, {get_user_field_values|array_first_value field='preferred_name'}</p>
Assigning to a named variable
{get_user_field_values field='my_field' item='my_variable'}
Using this method signature will assign the result to a variable named according to the item
parameter. This is useful where the User Field is intended to hold multiple values and you wish to iterate through the values within the template using a loop.
Data Restrictions
For performance reasons user field data is stored in the user session and the amount of data stored in the session is restricted.
User Additional Fields can contain multiple values. So for example a field might be defined such as also_known_as
. For a single user this field might have multiple values (named). To ensure this is performant, we cannot store unlimited data for each user within this field.
The following describes a system to ensure the number of values allowed will not affect system performance. Rather then setting an arbitrary number of values and an arbitrary size limit per value, we will total the number of Bytes for all values for a specific field.
User field values will be omitted once the combined length of field values exceeds 1024 bytes, per field.
With these restrictions and given that a maximum of 20 User Additional Fields are available to the templates, up to a total of 20 x 1024 bytes (20KB) of user field values data will be available.
If a field has its values restricted in this way a Smarty warning is logged to the Aurora Debug Bar.
The following table shows some scenarios for how this will work with different sized field values. Each colour separate colour band represents a different field (field_a, field_b etc). It shows that once values within that field go over 1024B, they will be omitted from the data.
Field | Value Index | Value Size | Result | Remarks |
---|---|---|---|---|
field_a | 0 | 100B | Allowed ✅ | |
- | - | - | - | |
field_b | 0 | 200B | Allowed ✅ | |
field_b | 1 | 300B | Allowed ✅ | |
- | - | - | - | |
field_c | 0 | 1100B | Omitted ❌ | Greater than 1024B |
- | - | - | - | |
field_d | 0 | 600B | Allowed ✅ | |
field_d | 1 | 600B | Omitted ❌ | 600B + 600B = 1200B (Greater than 1024B) |
- | - | - | - | |
field_e | 0 | 700B | Allowed ✅ | |
field_e | 1 | 200B | Allowed ✅ | 700B + 200B = 900B |
field_e | 2 | 400B | Omitted ❌ | 900B + 400B = 1300B (Greater than 1024B) |
Updated 16 days ago