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.
string $flag
The name of the insert tag flag.
string $tag
The name of the insert tag.
string $cachedValue
The cached replacement for this insert tag (if there is any).
array $flags
An array of flags used with this insert tag.
bool $useCache
Indicates if we are supposed to cache.
array $tags
Contains the result of spliting the page’s content in order to replace the insert tags.
array $cache
The cached replacements of insert tags found on the page so far.
int $_rit
Counter used while iterating over the parts in $tags
.
int $_cnt
Number of elements in $tags
.
The return value should be the replacement text or false
if the flag was not handled.
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;
}
}