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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Showing different headings on blog page

Solved by pamtbaau View solution

Started by John Green 5 years ago · 2 replies · 512 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 Pedro M, 2 months ago
4 222 2 months ago
Themes & Styling · by Ian, 2 months ago
3 118 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 481 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 72 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 132 3 months ago