Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Display page.summary without images in partials templates

Started by symac 9 years ago · 2 replies · 1491 views
9 years ago

Hello,
on my website ( http://www.geobib.fr/blog/ ) I use grav with theme purity which is fine but I don't really like that images are displayed as part of the truncated blog post like the green one just below :

Capture du 2018-01-10 11-17-45|690x274

According to template source it is page.summary that is used to display that part of text. I was looking for a filter that would remove the image before displaying the text, to have something that is more homogeneous amongst the posts that are listed.

Any idea on the best way to achieve that?

9 years ago

one option is to create a new custom header property like:

YAML
title: My Title
summary: My summary **intro text** without an image

Then modify your Twig to use {{ page.header.summary|markdown }}

Or you could simply use the |striptags filter on thepage.summary() - https://twig.symfony.com/doc/2.x/filters/striptags.html to remove any images.

9 years ago

Thanks @rhuk, I didn't know the striptags filter, so {{ page.summary | striptags("img") }} perfectly does the trick!

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by FrViPofm, 14 hours ago
1 29 2 hours ago
Themes & Styling · by stuart young, 1 month ago
3 480 1 month ago
Themes & Styling · by Sebadamus, 2 months ago
5 481 2 months ago
Themes & Styling · by martynfoster735, 2 months ago
1 460 2 months ago
Themes & Styling · by Justin Young, 2 months ago
1 490 2 months ago