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

Change the page title based on collection type/name

Solved by pamtbaau View solution

Started by Ian 11 months ago · 3 replies · 201 views
11 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
11 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
11 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

11 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 jean-louis67, 3 days ago
2 81 2 days ago
General · by Andy Miller, 7 days ago
0 146 7 days ago
General · by Veehem, 1 week ago
0 145 1 week ago
General · by milkboy, 1 week ago
0 138 1 week ago
General · by ian russell, 2 weeks ago
2 226 2 weeks ago