Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Twig variable with current month in the title of the post

Started by Muut Archive 10 years ago · 4 replies · 4645 views
10 years ago

So I want to include a variable with a name of the month in my page title so I don't need to update it manually every month.

So something like Best tools for X in {{ t("now"|date('M')) }}.

Of course it won't get the syntax right if I just add this to the page title so I am trying to find how can I achieve it without hardcoding it into templates.

10 years ago

For example:

TWIG
{% set month = 'now'|date('F') %}
{{ month }}

Using full month name, otherwise see PHP Date Formats

10 years ago

@OleVik that's clear to me. What I meant is I want to be able to use this {{ month }} tag in my admin dashboard in the title field and it will output correct month. But none of the variables are outputted there.

10 years ago

I'm not sure if the title field, in admin or with regular editing as text, will allow a dynamic Twig-tag in the title field. Is a conditional check of taxonomy in the template out of the question? With that you could just add the in Month after the title of the page, based on the publish-date, without needing dynamic tags in FrontMatter.

10 years ago

Yes I did something similar. I tag in header timecritical: true and this will add extra part after title of the post in twig template.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4065 9 years ago
Archive · by Muut Archive, 9 years ago
1 2953 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago