(v3.6.42)
Displays a custom field to the user when editing the content type. The field's value is then output within the template.
{{ element(type, label[, options]) }}
Use Twig syntax to handle the returned value:
- Output the field's value within the template:
{{ element('text', 'Label') }} - Assign the value to a variable:
{% set value = element('text', 'Label') %} - Use the value within a condition:
{% if element('text', 'Label') %} Do something... {% endif %}
Additional options
A 3rd parameter is used by elements to provide additional options, which are with required or optional depending on the element type. These options must be provided as a valid JSON string. e.g.
{{ element('select', 'Colours', {"firstOptions":"Select...","options":{"red":"Red","green":"Green","blue":"Blue"}}) }}
Generic options
All fields accept the following options:
tooltip
Displays a help icon adjacent to the element's label which displays a popup containing the tooltip.
{{ element('text', 'Label', {"tooltip":"Lorem ipsum dolor sit amet"}) }}
Field types
text
Displays a text input field.
{{ element('text', 'Label') }}
textarea
Displays a textarea field.
{{ element('textarea', 'Label') }}
texteditor
Displays a WYSIWYG text editor.
{{ element('texteditor', 'Label') }}
checkbox
Displays a checkbox.
{{ element('checkbox', 'Label') }}
select
Displays a select menu.
{{ element('select', 'Label') }}
Additional options
-
firstOptionPopulates the first option of the select menu -
optionsUsed to specify the select menu's options. Options can be specified as either an object or an array. - As an array:
{"options":["Red","Green","Blue"]} - An object:
{"options":{"red":"Red","green":"Green","blue":"Blue"}}
category
Displays a browse button that opens a modal listing the items of a component, allowing the user to select one or more items from the component. The IDs of the items selected are output by the function.
{{ element('category', 'Label', {"tableName":"blog_categories"}) }}
Additional options
-
tableNameREQUIRED - The name of the table from which to present the categories. -
selectLimitAccepts an integer representing the maximum number of items which may be selected. - If not set then no restriction is imposed.
- Set to 1 to only allow a single selection e.g:
{{ element('category', 'Author', {"tableName":"authors","selectLimit":1}) }}
link
Displays a combination of form fields allowing the user to configure a link to either a page, a page's content or a URL.
{{ element('link', 'Label') }}
Additional options
-
optionsAccepts a string consisting of any of the following of letters: -
i- Internal - Displays a browse button that opens the site tree modal. -
e- External - Displays a text field allowing users to submit a URL. -
p- Page link - Allows users to select pages from the site tree modal. -
c- Content link - Allows users to select content from the site tree modal. -
t- Target - Displays a select menu allowing users to specific the links target option.
{{ element('link', 'Label', {"options":"iepct"}) }}