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)11103.5k↓55%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 3y 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 3d 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 69% of packages

Maintenance9

Infrequent updates — may be unmaintained

Popularity41

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

3820d 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

[symfony/ux-twig-component

Twig components for Symfony

22018.6M357](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1647.0M128](/packages/symfony-ux-live-component)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

16126.1k1](/packages/symfony-ux-toolkit)[mati365/ckeditor5-symfony

CKEditor 5 integration for Symfony

262.6k](/packages/mati365-ckeditor5-symfony)

PHPackages © 2026

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