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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Change the page title based on collection type/name

Solved by pamtbaau View solution

Started by Ian 10 months ago · 3 replies · 67 views
10 months ago

I’m new to grav.

I’ve managed to create a new theme based off pure-blind for a blog with tags and an archive sidebar. All working nicely. When I click on a tag, or on an archive link it helpfully takes me to a new page with just the entries in the appropriate collection. However, the page title does not say anything about the filter.

I changed the theme to AntiMatter and it doesn’t seem to have that facility either. I’ve dumped the page variable and I can’t see what anything in that which would help.

Is there an easy way of getting the collection type & details so I can change the page title to something like:

  • Posts from July 2024
  • Posts tagged “Food”
👍 1
10 months ago Solution

@Slartibartfast, You can get the selected tag from the Uri using uri.param():

TWIG
{{ dump(uri) }}               // the Uri object
{{ dump(uri.params) }}        // all parameters
{{ dump(uri.param('tag')) }}  // a single specific parameter => "photography"
{{ dump(uri.param('archives_month')) }}  // a single specific parameter => "aug_2017"

See the docs: Class: \Grav\Common\Uri

👍 1
last edited 08/25/25 by pamtbaau
10 months ago

hello,
let me ask if these are right

  • you have a page that opened like this > https://demo.getgrav.org/blog-skeleton/tag:travel#body-wrapper
  • and you have a title like this > Home | Grav
  • but you want title like this > Home - Travel | Grav

@pamtbaau helped nicely with giving most important part, the code to get date and tag.
After that you can merge them with your page's title by using twig in template like set title = title ~ tag ~ date

10 months ago

Thank you! I’d not spotted the URI class.

For the record I’ve currently settled on

TWIG
    {% if uri.param('tag') %}
    <h1>Posts tagged {{ uri.param('tag') }}</h1>
    {% elseif uri.param('archives_month') %}
    <h1>Posts from {{ uri.param('archives_month') | date('F Y') }}</h>
    {% else %}
    {{ page.content|raw }}
    {% endif %}
👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 8 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago