Question

In Liquid, I'm aware you can do {% content | truncate:64 %} to truncate 64 characters and {% content | truncatewords:100 %} to truncate 100 words, but is there any way to truncate by a given number of paragraphs?

Was it helpful?

Solution

I had a similar issue. Maybe you can do something like this:

{% assign truncatedContent = '' %}
{% assign paragraphs = post.content | split:'</p>' %}
{% for paragraph in paragraphs limit:N %}
    {{ truncatedContent | append: paragraph }}
    {{ truncatedContent | append: '</p>' }}
{% endfor %}

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top