5

In D8.1, I have created a field called field_date and added it to a content type.

I try to use pathauto to try to configure a URL pattern for the content type like type/year/title. But the token browser does not expose expandable date options for date_field. If I enter it manually, I get "The Path pattern is using the following invalid tokens: [node:field_datetime:custom:Y]."

How can I format the output of a token for a date field, the same way I can for a node property like date created?

I've searched the issue queues for contrib token, core datetime and core token system, but I find nothing about this.

3 Answers 3

2

In the Manage Display section of your content type can control the output of your date field token.

Under Custom Display Settings, make sure the Token checkbox is set so you can adjust your token display. Once set, you can navigate to the Token tab where you can set your date field's Format to Custom and add your custom PHP date() string in the Date/time format field.

enter image description here

3
  • Thanks, this is useful if you want to show the data always in the same format when using tokens. Do you also know how to use different formats? So is it possible to have multiple view-modes for tokens?
    – dmsmidt
    Jul 21, 2016 at 10:27
  • You're better off asking this as a separate question.
    – Shawn Conn
    Jul 22, 2016 at 1:36
  • What a strange use of view modes!
    – Brian
    Jan 24, 2019 at 0:30
5

The Token module added direct support for datetime and daterange fields in December 2016. See https://www.drupal.org/project/token/issues/2786181.

You should be able to use something like [node:field_datetime:date:custom:Y]

-1

Another option is to use:

[node:field_[YOUR-CONTENT-TYPE]_date:0:date:custom:Y]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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