How Do I Display a Month and Year Only Time Format

I have a blog page with item subpages. When I try to change the time format in the blog page settings to m-Y(and click “add m-Y”), it reverts to “guess automatically” every time! I’m quite frustrated.

The pages themselves need actual dates that can be fully parsed. But what you display is up to you. So change your templates to ignore the day, but still enter a day when creating a page. Sorry if I’m misunderstanding your dilemma.

I can reproduce the behaviour mentioned by the OP.

Maybe the behaviour of the dateformat field might be a bit confusing…

I have never used it, but just had a look at the definition and made some assumptions based on that…

This is the field definition (/system/blueprints/pages/default.yaml):

  toggleable: true
  type: select
  size: medium
  selectize:                <- no docs found on this option
    create: true
  data-options@: '\Grav\Common\Utils::dateFormats'
    type: string

It is a ‘select’ box, but has a property ‘selectize’ (found no documentation on this option) which allows the user to enter free input.

This free input value is saved correctly to the frontmatter of the page, but isn’t stored anywhere to become part of the fixed list of options (data-options@).
Since the custom value doesn’t occur in the fixed list of data format options, the placeholder (“guess automatically”) will be shown.

Btw., in a field defined as ‘selectize’ you can truly add items to a list (like taxonomy types) which is stored in frontmatter.

Again, i’m just guessing based on code and observation of behaviour…

Maybe it could be an idea to have the method Utils::dateFormats() add the value saved in frontmatter to the list of options. I’ve tried a few things but don’t know how to get the current page and its header…

NB. According the sourcecode, the list of options can be extended with a single default value in /user/config/system.yaml:

    default: 'd-m-Y'

Unfortunately, the format ‘m-Y’ throws an error upon saving the page: “DateTime::__construct(): Failed to parse time string (11-2017)”

I’m afraid you’ll have to tweak the dateformat when printing in Twig…

1 Like