2

In Druapl 8, how can i change the date format used in a view (see screen shot)

enter image description here

The view uses a replacement pattern {{ created }} == Authored on

and i don’t find where to modify the format. I’ve checked :

configuration / regional and language / date and time formats

But i don’t know how to use the custom format with {{ created }} in the view.

Could it be done in admin without modify template file ?

2

In Drupal 8, fields use the normal field formatters. In your list of Fields in the View, click on Content: Authored on (Authored on). You can change the Formatter to what you want (same choices as Manage Display on the content type configuration). You can then configure other options, like the format.

If you already are using {{ created }} in the template, and you need it in a different format for a replacement pattern / token, then add Content: Authored on (Authored on) again to the list of Fields, but exclude it from display. Reorder things, so this appears before the field you need it as a token. Configure it as above. Then, where you need the token, you should have {{ created_1 }}, which is the duplicate you just made.

  • Thanks, it was simple but i was not familiar with this. – Sébastien Gicquel Feb 17 '17 at 16:22
0

I havent try, but if you can use some twig maybe with something like that:

{{created|format_date("name_of_your_format")}}

Or

{{created.value|format_date("name_of_your_format")}}

maybe try to inspect that 'created' variable with a {{dump(created)}} Hope, it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.