Skip to content

KirbyTags: (date: year) does not reset cache on New Year's Day #7746

@nilshoerrmann

Description

@nilshoerrmann

Description

When using the KirbyTag (date: year), the current year is returned automatically. If the HTML output is cached, it will not be reset on New Year's Day.

Expected behavior
When (date: year) is used on a page, the cache should expire on New Year. This can be achieved by adding the following line before returning the date:

kirby()->response()->expires('midnight first day of next year');

Your setup

Kirby Version
Kirby 5.1 and all versions before.

Additional context
It might be interesting to add an expiry attribute to the tag, to allow for custom expiries set by the author:

	/**
	 * Date
	 */
	'date' => [
		'attr' => [
			'expiry'
		],
		'html' => function (KirbyTag $tag): string {
			kirby()->response()->expires($tag->expiry ?? 'midnight first day of next year');

			if (strtolower($tag->date) === 'year') {
				return date('Y');
			}

			return date($tag->date);
		}
	],

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions