Haste provides several insert tags for everyday use. They are not related to Haste functionality but for general use in a Contao environment.
The sole purpose of this insert tag is to pass a value to the insert tag flags.
Example: {{flag::foobar|strtoupper}}
will return FOOBAR
.
See the Contao documentation for available flags.
The formatted_datetime
insert tag allows to format a timestamp or a
PHP date/time format (see http://php.net/manual/en/function.strtotime.php)
using either the internal date/time formatting settings or a custom
format.
-
{{formatted_datetime::1234::d.m.Y}}
Formats the timestamp1234
to Day.Month.Year. Available formatting options can be found in the PHPdate
method. -
{{formatted_datetime::1234::date}}
Formats the timestamp1234
to the system's date format. -
{{formatted_datetime::1234::time}}
Formats the timestamp1234
to the system's time format. -
{{formatted_datetime::1234::datim}}
Formats the timestamp1234
to the system's date + time format. -
{{formatted_datetime::+1 day::datim}}
Formats the timestamp ofnow +1 day
to the system's date + time format. -
{{formatted_datetime::+1 week 2 days 4 hours 2 seconds::d.m.Y}}
Formats the timestamp ofnow +1 week 2 days 4 hours 2 seconds
to Day.Month.Year. Available formatting options can be found in the PHPdate
method.
The convert_dateformat
insert tag allows to convert the provided
date/time from one format to another. It takes the following format:
{{convert_dateformat::<value>::<source_format>::<target_format>}}
The source_format
and target_format
can be any format from PHP date
method
or date
/ datim
/ time
to take the the format from the root page settings
(or system settings, in case not defined).
-
{{convert_dateformat::2018-11-21 10:00::datim::date}}
Converts the provided date and time to date only2018-11-21
. -
{{convert_dateformat::21.03.2018::d.m.Y::j. F Y}}
Converts the provided date to another format21. März 2018
. Multilingual formats are supported thanks toContao\Date
class.
Sometimes it is necessary to get the label of a form generate option (e.g. a radio button or checkbox field) from it's value.
Example: {{options_label::1::value}}
- First argument is the form field ID from form generator
- Second argument is the field value
If the field is not found or does not have a matching option, the original value will be returned.
Particular use cases are in the Notification Center extension, where
simple tokens are available for input field values. By entering
{{options_label::17::##form_fieldname##}}
into the notification text,
one can output the option label of field ID 17.
{{dca_label::tl_article::title}}
will output the label
for the DCA field title
of table tl_article
.
{{dca_value::tl_article::title::17}}
will output the formatted
title
value of table tl_article
record ID 17.
The insert tag is following the Contao's standards on value formatting.
As example, if the given field has a foreignKey
attribute set,
the returned value will be looked up in the foreign table.
The following checks are performed:
- If DCA field has a
foreignKey
, lookup result in the foreign table. - If value is an array, recursively resolve and implode to a comma-separated list.
- If DCA field input is a date (
rgxp => date
), format value as date string - If DCA field input is a time (
rgxp => time
), format value as time - If DCA field input is a date + time (
rgxp => datim
), format value as date + time string - If DCA field is a single checkbox, return
yes
orno
labels - If DCA field allows HTML input, encode the string so the HTML code is visible
- If DCA field has
reference
set, try to find the value in thereference
array - If DCA field has
options
, try to find the value in theoptions
array
-
Simple version:
{{rand}}
Generates a random number using PHP'smt_rand
method. -
Extended version:
{{rand::1::100}}
If you pass two arguments to the insert tag, you can define the minimum and maximum value (seemt_rand
documentation).