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
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
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-05