Register a specific twig-filter for locale specific date
4
Use the registerMarkupTags
method in the Plugin.php
to register a twig-filter for a locale specific date.
public function registerMarkupTags()
{
return [
'filters' => [
'germanDate' => function ($date_time, $format) {
$carbon = new Carbon($date_time);
setlocale(LC_ALL, 'German');
return utf8_encode($carbon->formatLocalized($format));
},
],
];
}
Now simply use the new filter in your twig files:
{{ '2019-01-16' | germanDate('%e. %B %Y') }} // 1. Januar 2019
There are no comments yet
Be the first one to comment