getgrav / grav-premium-issues

Official Grav Premium Issues repository to report problems or ask questions regarding the Premium products offered.
https://getgrav.org/premium
7 stars 2 forks source link

[typhoon] line breaks in blog post previews #434

Closed thebasti314 closed 2 months ago

thebasti314 commented 2 months ago

The preview texts in the blog overview page (Twig origin: post-item.html.twig) do not contain line breaks, although there are some in the original text.

I've been searching for hours, but can't find the right setting for change this.

Many thanks for your support.

Typhoon v2.4.6

rhukster commented 2 months ago

The preview text that is shown in the blog listing page with the cards that are rendered via the post-item.html.twig is actually stripping the HTML tags so that the cards are not congested with rendered HTML like titles, paragraphs etc.

You can change this behavior by modifying your post-item.html.twig and changing the second paramater of the page.summary() method to false rather than true. I've broken it out into separate variables to make things a bit simpler:

{% set page_summary = page.summary(null, false) %}
{% set summary_length = 170 %}
{% set summary_size = bg_image ? (page_summary|length < summary_length ? page_summary : page.summary(summary_length, false)) : page_summary %}

You might want to play with that 170 value until things look right to you.

The last line there uses an inline logic that converts to:

if there's a bg_image, check if page_summary length with default site.summary length is smaller than defined summary_length (170), if so, just use page_summary, if its greater than that, get the page summary with length of 170. If no bg_image, simply use the page_summary as is.