Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top