Opened 10 years ago

Closed 10 years ago

#23914 closed New feature (fixed)

Allow the {% now %} tag to store its output in the context

Reported by: Baptiste Mispelon Owned by: Baptiste Mispelon
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I hit this issue when trying to use the value of the current year inside a translated string.

Normally, you'd do something like this:

{% blocktrans %}Current year: {% now 'Y' %}{% endblocktrans %}

But this doesn't work because blocktrans doesn't allow other tags inside.

So I propose adding the as varname syntax to {% now %} so you can do something like this:

{% now 'Y' as current_year %}
{% blocktrans %}Current year: {{ current_year }}{% endblocktrans %}

Change History (3)

comment:1 by Baptiste Mispelon, 10 years ago

Has patch: set

comment:2 by Tim Graham, 10 years ago

Triage Stage: UnreviewedReady for checkin
Version: 1.6master

comment:3 by Baptiste Mispelon <bmispelon@…>, 10 years ago

Resolution: fixed
Status: newclosed

In c335c0fee92a658b6a09453ae73e5c542f10703a:

Fixed #23914 -- Improved {% now %} to allow storing its result in the context.

Thanks to Tim for the review.

Note: See TracTickets for help on using tickets.
Back to Top