Is it possible to show the current date in query language?

My use case is that I’d like to use the current year in a blueprint for a copyright field. On the front end the year will be pulled in automatically so the client doesn’t need to worry about keeping it up to date.

My blueprint field looks like this:

copyright_text:
  label: Copyright Text
  type: text
  before: "© {{ date('Y') }}"

At the moment the date part of this does not display.

Does anyone know if something like this is possible?

Thanks,
Chris

If the copyright year is always the current year, I wouldn’t save it in a blueprint. Rather put it in the template as a PHP echo.

Another idea would be to have a read-only field in the blueprint and update it with a page.update:after hook after changing the article. Keep in mind: If the page isn’t updated regularly, the copyright year might be outdated/wrong.

before property won’t work here I think. It is used to set an Optional text that will be shown before the input. It’s not actual input saved in a file I think. It’s like an usability help for the user to tell him what to type into the field.

I think that is exactly the purpose here.


I just tested it and indeed, using date('Y') doesn’t work here. But we can use a little trick:

    copyright_text:
        label: Copyright Text
        type: text
        before: "© {{ page.year }}"

The in a page model or a page method named year(), return the date:

class SomePage extends Page
{
    public function year()
    {
        return date('Y');
    }
}

If you use this in the site.yml, use a custom site method.

1 Like

Ah that’s good to know then. I thought that it’s like the placeholder HTML attribute due to the description. Thank you for correcting me.