4

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?

1 Answer 1

7

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.

1
  • Absolutely spot on, nice one.
    – Bolster
    Feb 6, 2014 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.