Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Showing different headings on blog page

Solved by pamtbaau View solution

Started by John Green 5 years ago · 2 replies · 715 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 FrViPofm, 4 weeks ago
4 490 3 weeks ago
Themes & Styling · by johan thomas, 5 years ago
1 811 3 weeks ago
Themes & Styling · by stuart young, 2 months ago
3 669 2 months ago
Themes & Styling · by Sebadamus, 3 months ago
5 690 2 months ago
Themes & Styling · by martynfoster735, 3 months ago
1 652 3 months ago