PHPackages                             sachleen/twig-truncatep - 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. sachleen/twig-truncatep

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

sachleen/twig-truncatep
=======================

A Twig Extension filter to truncate html by number of p tags

1.0(8y ago)029MITPHP

Since Dec 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/sachleen/Twig-TruncateP)[ Packagist](https://packagist.org/packages/sachleen/twig-truncatep)[ RSS](/packages/sachleen-twig-truncatep/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Twig-TruncateP
==============

[](#twig-truncatep)

Truncates a HTML by number of `` tags. This is useful for showing summaries of blog posts where normal truncate functions will not preserve HTML syntax. Since blocks of text should be within paragraph tags, there are no issues of missing HTML tags or HTML tags counting against the letter or word count of the truncated string. Simply specify how many `` tags you would like to see and that's what you'll get.

Install
-------

[](#install)

With composer

```
composer require sachleen/twig-truncatep

```

Usage
-----

[](#usage)

To use the extension, add it to your Twig object.

```
$twig = new Twig_Environment($loader);
$twig->addExtension(new \Sachleen\Twig\TwigTruncatePExtension());
```

Use TruncateP in your template to truncate any html variable to a specific number of p blocks. All parameters are optional.

```
{{ post.content|TruncateP()|raw }}
{{ post.content|TruncateP(2)|raw }}
{{ post.content|TruncateP(2, 'Continue Reading...')|raw }}
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Unknown

Total

1

Last Release

3115d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/579603?v=4)[Sachleen Sandhu](/maintainers/sachleen)[@sachleen](https://github.com/sachleen)

---

Top Contributors

[![sachleen](https://avatars.githubusercontent.com/u/579603?v=4)](https://github.com/sachleen "sachleen (1 commits)")

### Embed Badge

![Health badge](/badges/sachleen-twig-truncatep/health.svg)

```
[![Health](https://phpackages.com/badges/sachleen-twig-truncatep/health.svg)](https://phpackages.com/packages/sachleen-twig-truncatep)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)

PHPackages © 2026

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