insertTagFlags
The insertTagFlags hook is triggered when unknown flags (filters) are passed
to an insert tag. It passes the arguments listed belows and expects the replacement
text as return value or false if the flag was not handled.
Note
Using the insertTagFlags hook has been deprecated and will no longer work in Contao 6. See
here on how to register custom insert tag flags.
Parameters
string
$flagThe name of the insert tag flag.
string
$tagThe name of the insert tag.
string
$cachedValueThe cached replacement for this insert tag (if there is any).
array
$flagsAn array of flags used with this insert tag.
bool
$useCacheIndicates if we are supposed to cache.
array
$tagsContains the result of spliting the page’s content in order to replace the insert tags.
array
$cacheThe cached replacements of insert tags found on the page so far.
int
$_ritCounter used while iterating over the parts in
$tags.int
$_cntNumber of elements in
$tags.
Return Values
The return value should be the replacement text or false if the flag was not handled.
Example
If you use {{date::D d. F Y|monthNamesAustria|utf8_strtoupper}} Contao knows
how to handle the date insert tag and the utf8_strtoupper flag. The unknown
monthNamesAustria triggers the hook:
// src/EventListener/InsertTagFlagsListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('insertTagFlags')]
class InsertTagFlagsListener
{
public function __invoke(
string $flag,
string $tag,
string $cachedValue,
array $flags,
bool $useCache,
array $tags,
array $cache,
int $_rit,
int $_cnt
)
{
if ('monthNamesAustria' === $flag) {
return str_replace(['Januar', 'Februar'], ['Jänner', 'Feber'], $cachedValue);
}
// Indicate that we did not handle that flag
return false;
}
}