Score:0

Converting date in field-created.html.twig

kp flag

node-created.html.twig to override some html. That works fine. Although the date is being displayed as Thu, 04/28/2022 - 11:39 which I want to be something like May 2, 2023. Is this possible within this piece of twig code?

{%
  set classes = [
    'field',
    'field--name-' ~ field_name|clean_class,
    'field--type-' ~ field_type|clean_class,
    'field--label-' ~ label_display,
    'created-label',
  ]
%}
<span{{ attributes.addClass(classes) }}>
  {%- for item in items -%}
    {{ item.content }}
  {%- endfor -%}
</span>
cn flag
That is not the template you want. You probably want the field template for the date field for whatever node/content type you want to change it for. Please update your question with more details about what you are trying to do. Also, note that you can edit how dates are displayed without any coding at `/admin/config/regional/date-time`.
user108721 avatar
kp flag
@PatrickKenny It's just the authored on field, which is the exact template I currently use. And I only need to edit the date format that is shown for a specific node.
Score:0
cn flag

As a learning experience

I suggest you look at the twig date function https://twig.symfony.com/doc/3.x/filters/date.html

{{ field_crated|date("m/d/Y") }}
  or 
 {{ crated|date("m/d/Y") }}

then also if that does not work

 function THEME_preprocess_field__node(&$variables) {
   
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.