How can I modify blog.html.twig
(e.g. in the Quark theme) so that it displays a different heading depending on whether I’m on:
- the blog page itself (URL is
/blog
) - I want to see “Blog”
- have arrived by clicking on a tag (URL is
/tag:mytag
) - I want to see “Subject: mytag”
- using the Archives plugin (URL is
/archives_month:may_2021
) - I want to see “Month: May 2021”
Bonus: Is this described somewhere in the manual, so that I can bookmark it? Or is there a way I could discover the solution through debugging?
@johnsgp, You could use Uri to get the params.
An unpolished example:
{% set params = uri.params(null, true) %}
{% if not params %}
<p>Blog</p>
{% elseif params['archives_month'] %}
{% set period = params['archives_month'] | split('_') %}
<p>Month: {{ period[1] }} {{ period[0] | capitalize}} </p>
{% elseif params['tag'] %}
<p>Subject: {{ params['tag'] | capitalize }}</p>
{% endif %}
1 Like
Thanks @anon76427325 - that is absolutely spot on! I didn’t think of using the URI params. I also found the reference in the documentation, at Theme Variables | Grav Documentation