Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Showing different headings on blog page

Solved by pamtbaau View solution

Started by John Green 5 years ago · 2 replies · 805 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 MarkP, 2 weeks ago
3 193 2 weeks ago
Themes & Styling · by TomW, 2 weeks ago
0 111 2 weeks ago
Themes & Styling · by themetman, 3 weeks ago
1 206 3 weeks ago
Themes & Styling · by AH, 1 month ago
1 324 3 weeks ago
Themes & Styling · by Bruno, 4 years ago
6 1523 3 weeks ago