PHPackages                             bluetel-solutions/twig-truncate-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. bluetel-solutions/twig-truncate-extension

ActiveLibrary[Templating &amp; Views](/categories/templating)

bluetel-solutions/twig-truncate-extension
=========================================

Twig Extension to truncate nested HTML, safely!

v0.1.3(10y ago)11100.0k↓35.4%13[6 issues](https://github.com/Bluetel-Solutions/twig-truncate-extension/issues)[6 PRs](https://github.com/Bluetel-Solutions/twig-truncate-extension/pulls)MITPHPPHP &gt;=5.3.0

Since Nov 5Pushed 2y ago4 watchersCompare

[ Source](https://github.com/Bluetel-Solutions/twig-truncate-extension)[ Packagist](https://packagist.org/packages/bluetel-solutions/twig-truncate-extension)[ RSS](/packages/bluetel-solutions-twig-truncate-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Twig Truncation Extension
=========================

[](#twig-truncation-extension)

[![Build Status](https://camo.githubusercontent.com/b034bef5419c2087e2edeaf90a71b12cdce55ae69982a500deab3bcf7baf43e9/68747470733a2f2f7472617669732d63692e6f72672f426c756574656c2d536f6c7574696f6e732f747769672d7472756e636174652d657874656e73696f6e2e737667)](https://travis-ci.org/Bluetel-Solutions/twig-truncate-extension)

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](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) 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
------------------------

[](#truncating-on-word-count)

```
{% set html %}
    Test heading!

        Hello world
        Foo bar
        Lorem Ipsum

{% endset html %}
{{ html|truncate_words(5) }}
```

Running this returns:

```
Test heading!

    Hello world
    Foo

```

Truncating on character count
-----------------------------

[](#truncating-on-character-count)

```
{% set html %}
    Test heading!

        Hello world
        Foo bar
        Lorem Ipsum

{% endset html %}
{{ html|truncate_letters(20) }}
```

Whereas running the above returns the following:

```
Test heading!

    Hello wo

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance9

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Total

4

Last Release

3773d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/440052?v=4)[Alex Wilson](/maintainers/alexwilson)[@alexwilson](https://github.com/alexwilson)

---

Top Contributors

[![alexwilson](https://avatars.githubusercontent.com/u/440052?v=4)](https://github.com/alexwilson "alexwilson (7 commits)")

---

Tags

twigtwig-extensiontruncate

### Embed Badge

![Health badge](/badges/bluetel-solutions-twig-truncate-extension/health.svg)

```
[![Health](https://phpackages.com/badges/bluetel-solutions-twig-truncate-extension/health.svg)](https://phpackages.com/packages/bluetel-solutions-twig-truncate-extension)
```

###  Alternatives

[twig/extra-bundle

A Symfony bundle for extra Twig extensions

91492.0M315](/packages/twig-extra-bundle)[twig/intl-extra

A Twig extension for Intl

36763.2M221](/packages/twig-intl-extra)[twig/string-extra

A Twig extension for Symfony String

22046.0M133](/packages/twig-string-extra)[dzango/twig-truncate-extension

A Twig extension to truncate text while preserving HTML tags

13238.9k2](/packages/dzango-twig-truncate-extension)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
