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

Showing different headings on blog page

Solved by pamtbaau View solution

Started by John Green 5 years ago · 2 replies · 626 views
5 years ago

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?

5 years ago Solution

@johnsgp, You could use Uri to get the params.

An unpolished example:

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

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by stuart young, 2 weeks ago
3 251 2 weeks ago
Themes & Styling · by Sebadamus, 3 weeks ago
5 317 3 weeks ago
Themes & Styling · by martynfoster735, 4 weeks ago
1 310 4 weeks ago
Themes & Styling · by Justin Young, 1 month ago
1 348 1 month ago
Themes & Styling · by Slebeig, 2 months ago
4 474 2 months ago