定制 bluetel-solutions/twig-truncate-extension 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bluetel-solutions/twig-truncate-extension

最新稳定版本:v0.1.3

Composer 安装命令:

composer require bluetel-solutions/twig-truncate-extension

包简介

Twig Extension to truncate nested HTML, safely!

README 文档

README

Build Status

This extension attempts to solve a common problem, namely that of truncating HTML content based on the number of characters and on the number of words contained.

Other libraries we have tried attempt to manipulate the HTML content by means of regular expressions which is liable to break, and always seems to at the worst times, hence the need for this extension. This leverages the power of DOMDocument to safely truncate even the most complex of nested HTML documents.

Truncating on word count

{% set html %}
    <h1>Test heading!</h1>
    <ul>
        <li>Hello world</li>
        <li>Foo bar</li>
        <li>Lorem Ipsum</li>
    </ul>
{% endset html %}
{{ html|truncate_words(5) }}

Running this returns:

<h1>Test heading!</h1>
<ul>
    <li>Hello world</li>
    <li>Foo</li>
</ul>

Truncating on character count

{% set html %}
    <h1>Test heading!</h1>
    <ul>
        <li>Hello world</li>
        <li>Foo bar</li>
        <li>Lorem Ipsum</li>
    </ul>
{% endset html %}
{{ html|truncate_letters(20) }}

Whereas running the above returns the following:

<h1>Test heading!</h1>
<ul>
    <li>Hello wo</li>
</ul>

统计信息

  • 总下载量: 96.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 4
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-05