bluetel-solutions/twig-truncate-extension 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固