Date format for short and long ignored


#1

Hi,

I just found something weird while configuring Grav for my new site. I wanted to set a date format for short and long dates, however, I wasn’t able to do it via the admin panel. So I decided to go to the command line and set it to system.yaml directly:

  dateformat:
    default: 'd.m.Y H:i'
    short: 'd.m.y'
    long: 'j. F Y H:i'

Now, when switching back to the admin panel and save the configuration once again will ignore your settings in system.yaml and set it to:

  dateformat:
    default: 'd.m.Y H:i'
    short: 'F jS \a\t g:ia'
    long: 'F jS \a\t g:ia'

This is somehow weird … seems that the admin panel lets you at least define the default date format, but ignores everything else regarding date.

Regards, Thomas


#2

Hi Thomas,
this is probably a little late, but as I just had the same issue, I am going to reply anyway:

The reason for this strange behaviour IMHO is the admin panel. Same as when you do it manually, the admin panel writes all configurations into the user/config/system.yaml file. So, when you manually edit the system.yaml and save something afterwards directly from the admin panel, it overwrites this file.
This must be combined with the fact, that the select options in the admin panel are based on what Grav calls “blueprints”. Stating from Grav’s documentation:

[Blueprints] are essentially the foundation of a theme or plugin’s interaction with the Grav admin. They tell Grav what a theme or plugin is, its name, where it can be found on GitHub, etc. It also generates the configuration options for that theme or plugin in the Grav admin.

These blueprints currently do not include the date format you are looking for. In fact, they do not show up in the select lists for default, long or short dates. Not even, if you enter them manually in the system.yaml.
But you can add them to the blueprint, so that they do show up and you can select them directly from the admin panel and therefore are not overwritten, when saving any configuration from the admin panel. You can do it like this:

Create a new file called system.yaml in the folder user/blueprints/config. You may need to create these folders; they are probably not there by default:

And then, add the following file content:

@extends:
    '@parent'
 
     form:
        fields:
            content:
                fields:
                    pages.dateformat.short:
                        options:
                            "d M Y": Date6
 
                    pages.dateformat.long:
                        options:
                            "d F Y, H:i": Date6

This adds another entry for the fields “Short display date format” and “Long display date format” at the end of the list, using the format that you specified.

Hope this (still?) helps. :slight_smile:
Sebastian


#3

Hi,

well, I stopped using Graf already a while ago. I mostly use Jekyll nowadays since I do not provide dynamic content, mostly static pages. Therefore I’m not in the need of a CMS anymore. But, hey, thanks for your reply, even the topic is already a little bit old. :slight_smile:

Regards, Thomas