【问题标题】:Liquid Templating: Truncate N paragraphs液体模板:截断 N 个段落
【发布时间】:2014-01-16 12:34:19
【问题描述】:

Liquid,我知道你可以做到 {% content | truncate:64 %} 截断 64 个字符,{% content | truncatewords:100 %} 截断 100 个单词,但是有没有办法截断给定数量的段落

【问题讨论】:

    标签: liquid templating


    【解决方案1】:

    我遇到了类似的问题。也许你可以这样做:

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

    希望对你有帮助。

    【讨论】:

    • 绝对准确,不错。
    猜你喜欢
    • 2012-06-06
    • 2011-08-22
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    相关资源
    最近更新 更多