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

Markdown truncate

Started by Muut Archive 10 years ago · 2 replies · 567 views
10 years ago

Hi,
I have a probleme with my blog :
On main blog page, all articles are diplayed with an image and a truncated text (beacause all article text is too long), but I discover a probleme today : my artucle are written with markdown.
The problem is when text is truncated, it keeps markdown tags, so I can have the first tag ("<p> for example) but not the last (</p>) because of the truncate.
That causes HTML issues of tags not correctly closed.

Can we display text without markdown in blog article previews when we truncate ?

Thanks,

Anne

10 years ago

I found this :

instead of writing {{ page.content|truncate(200) }}

we can write :

{% set somehtml = page.content %}
{{ somehtml[:200]|striptags ~ ' ...' }}

This is working, so I let the post, it can be helpful for someone else :)

10 years ago

Also you can use the manual truncate tag to pick a specific point where to truncate the blog for the listing page:

TXT
this will be shown in `page.summary()`

===

this will not be shown

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago