Change the page title based on collection type/name

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 Like

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

{{ 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 Like

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

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

For the record I’ve currently settled on

	{% 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 Like