October CMS resources and help articles

Simple and to the point. Optimized by the community.

Register a specific twig-filter for locale specific date

by OFFLINE, last modified on August 11th, 2019

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



We use cookies to measure the performance of this website. Do you want to accept these cookies?