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

Display element on blog list page and not blog page?

Started by colin avolve 9 years ago · 4 replies · 910 views
9 years ago

I am new to Grav (a few weeks of playing around with theming, reading docs), and I am still getting my head around a few things (including Twig)

In a sandbox site, I am exploring aspects of theming (a custom theme with inheritance from antimatter). One thing I am currently stuck on is how to display an element on a blog list page and not the individual blog page. I have yet to determine which variable I could use for this when editing a custom blog_item.html.twig template.

For context, I developed a number of Drupal themes over several years, and the approach I would take there was content-type based (equivalent to page v post in Wordpress) variables.

Any suggestions would be appreciated. As would links to any further guides/tutorials beyond the grave documentation.

9 years ago

what sort of element? is it something you could set in the page frontmatter, then in the listing page, simply see if that value is set, and if so, display it?

9 years ago

thanks @rhuk. Appreciate the reply.

I worked it out a couple hours ago — seem I missed a typo in my template, which led to my confusion.

I have now used

{% if truncate %}

and

{$ else %}

to achieve what I was seeking to

8 years ago

I actually have the same question. Could you explain how you use them? For example I don't want the tags on the blog listing page, but they should show with the post itself.

8 years ago

hi @Eli

in Antimatter theme you can remove tags from blog listing here
in partials/blog_item.html.twig

https://github.com/getgrav/grav-theme-antimatter/blob/develop/templates/partials/blog_item.html.twig#L26-L32

But it will remove from blog listing and blog single.

So one way to suit your needs (if i undersand well)
is to copy blog_item.html.twig rename to blog_item_single.html.twig but don't remove L26-L32

last thing it's to call the correct twig template when your are on your single post, to do so go to /templates/item.html.twig

https://github.com/getgrav/grav-theme-antimatter/blob/develop/templates/item.html.twig#L10

change
{% include 'partials/blog_item.html.twig' with {'blog':page.parent, 'truncate':false} %}
to
{% include 'partials/blog_item_single.html.twig' with {'blog':page.parent, 'truncate':false} %}

The best way is to use theme inheritance to do your changes without modify original theme

Hope that helps

Dimitri

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 196 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 126 3 months ago