PHPackages                             belniakmedia/craft-excerptify - 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. belniakmedia/craft-excerptify

ActiveCraft-plugin[Templating &amp; Views](/categories/templating)

belniakmedia/craft-excerptify
=============================

Provides the excerptify twig filter which truncates the provided variable's text or html to the nearest whole word based on the provided character length.

5.0.3(7mo ago)23.2kMITPHPPHP &gt;=8.0.2

Since Mar 12Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/BelniakMedia/craft-excerptify)[ Packagist](https://packagist.org/packages/belniakmedia/craft-excerptify)[ RSS](/packages/belniakmedia-craft-excerptify/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (8)Used By (0)

Excerptify Plugin for CMS 3.x
=============================

[](#excerptify-plugin-for-cms-3x)

Provides the `excertify` twig filter which truncates the provided variable's text or html to the nearest whole word based on the provided character length.

Parameters
----------

[](#parameters)

```
excerptify(int $characterCount, bool $forceBreakWord, null|string|array $allowedTags)

```

ParameterTypeDefaultDescription$characterCountint200Number of characters to limit result to.$forceBreakWordboolfalseWhen false, the text will be broken at the last occurring word break character. When true it will return the text up to the exact character limit, breaking a word if necessary.$allowedTagsnull|string|arraynullA string representing a single HTML tag or an array of strings representing HTML tags. *Added in 5.0.2*$trimboolfalseWhen enabled, will remove any non unicode letter or number characters at the end of the returned excerpt. If no visible text was was removed, then the trim does not occur. If HTML was allowed and left in when parsing the content, the &gt; character is also allowed when trimming would otherwise occur. *Added in 5.0.3*Usage Examples
--------------

[](#usage-examples)

---

### Prevent certain HTML tags from being stripped from the output

[](#prevent-certain-html-tags-from-being-stripped-from-the-output)

Pass a string or array of strings to the third parameter representing the tags that should not be removed:

```
{{ postContent | excerptify(200, false, '') }}

```

*This is a new feature as of 5.0.2*

### Trim left-over punctuation characters from the end of the returned excerpt

[](#trim-left-over-punctuation-characters-from-the-end-of-the-returned-excerpt)

Set the 4th parameter ($trim) to true:

```
{{ postContent | excerptify(200, false, '', true) }}

```

NOTE: Trimming is only performed, when enabled, if visible text was removed. Any non Unicode safe letter or number will be removed from the end. When HTML was allowed and left in for the text being processed, the end HTML character `>` is also allowed as to not accidentally scenarios where the text ended with an allowed HTML tag.

Enabling this feature will allow you to add your own ellipsis (...) after the excerpt in your use-case without fear of ending up with something like `however,...` which would be undesirable.

*This is a new feature as of 5.0.3*

> **WARNING:**
> If no visible text was removed then full string less non-allowed html tags will be returned and the trim will not occur. In this case, if the text you passed in ended with a period, the period will be retained in the output. You should test for this before blindly adding your ellipsis or other punctuation. I recommend two ways to accomplish this:
>
> 1. Get two copies of the excerpt from the filter where one uses a very high character count to ensure no text is removed, and also get your actual excerpt. You can compare the raw lengths of the values to determine if content was trimmed and handle it as needed:
>
> ```
> {% set fullText = postContent | excerptify(20000000, false, '', true) %}
> {% set excerpt = postContent | excerptify(200, false, '', true) %}
> {% set ending = '.' %}
> {% if fullText|length > excerpt|length %}
>    {% set ending = '...' %}
> {% endif %}
> {{ excerpt | raw }}{{ ending }}
> ```
>
>
>
> 2. Use a regex match to check if a non-word character is present at the end of the excerpt:
>
> ```
> {% set excerpt = postContent | excerptify(200, false, '', true) %}
> {% set ending = '.' %}
> {% if excerpt matches '/[^\p{L}\p{N}]+$/u' %}
>    {% set ending = '...' %}
> {% endif %}
> {{ excerpt | raw }}{{ ending }}
> ```

#### Break at nearest word

[](#break-at-nearest-word)

This is the default as in the same sas passing no arguments. Will return full words and the resulting string will not exceed 200 characters.

```
{{ postContent | excerptify(200) }}

```

To break exactly at the specified character count, even mid word, pass true for the forceBreakWord parameter:

```
{{ postContent | excerptify(200, true) }}

```

Brought to you by [Belniak Media Inc.](http://www.belniakmedia.com)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance62

Regular maintenance activity

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

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

Every ~335 days

Recently: every ~258 days

Total

7

Last Release

236d ago

Major Versions

1.0.1 → 2.0.02022-11-17

2.0.0 → 5.0.02024-06-20

PHP version history (2 changes)2.0.0PHP &gt;=8.0.0

5.0.0PHP &gt;=8.0.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebaede952a8bd243632f06aee5b30c529503a33ad07ddb59941f9c45898c883a?d=identicon)[RickKukiela](/maintainers/RickKukiela)

---

Top Contributors

[![RickKukiela](https://avatars.githubusercontent.com/u/3813238?v=4)](https://github.com/RickKukiela "RickKukiela (6 commits)")

---

Tags

cmsCraftcraftcmscraft-pluginexcerpttwig filterexcertpify

### Embed Badge

![Health badge](/badges/belniakmedia-craft-excerptify/health.svg)

```
[![Health](https://phpackages.com/badges/belniakmedia-craft-excerptify/health.svg)](https://phpackages.com/packages/belniakmedia-craft-excerptify)
```

###  Alternatives

[lewisjenkins/craft-dynamic-fields

Populate Craft fields with dynamic data using the power of Twig.

14667.0k](/packages/lewisjenkins-craft-dynamic-fields)[nystudio107/craft-minify

A simple plugin that allows you to minify blocks of HTML, CSS, and JS inline in Craft CMS templates.

37461.2k29](/packages/nystudio107-craft-minify)[jalendport/craft-preparse

A fieldtype that parses Twig when an element is saved and saves the result as plain text.

1086.4k](/packages/jalendport-craft-preparse)[craftpulse/craft-colour-swatches

Let clients choose from a predefined set of colours and utilise associated colour codes and class names in your templates.

3530.8k2](/packages/craftpulse-craft-colour-swatches)[verbb/footnotes

Adds a footnotes feature to CKEditor fields and Twig templates.

213.3k](/packages/verbb-footnotes)

PHPackages © 2026

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