PHPackages                             creative-sizzle/wn-twigextensions-plugin - 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. creative-sizzle/wn-twigextensions-plugin

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

creative-sizzle/wn-twigextensions-plugin
========================================

Register more Twig filters for your Winter CMS templates

1.2.6(6y ago)0101MITPHPPHP &gt;=7.0

Since Jan 4Pushed 4y agoCompare

[ Source](https://github.com/creative-sizzle/wn-twigextensions-plugin)[ Packagist](https://packagist.org/packages/creative-sizzle/wn-twigextensions-plugin)[ RSS](/packages/creative-sizzle-wn-twigextensions-plugin/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (28)Used By (0)

Twig extensions
===============

[](#twig-extensions)

[![Build Status](https://camo.githubusercontent.com/a7f70bd17562d2fde1500b702fe67d8eeac84e8f68b928ba2c4dd848efef6e66/68747470733a2f2f7472617669732d63692e6f72672f766f6a746173766f626f64612f6f632d74776967657874656e73696f6e732d706c7567696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vojtasvoboda/oc-twigextensions-plugin)[![Codacy](https://camo.githubusercontent.com/d0928423f50146df49b8eff752716b4074ad624fd2899665107a31290046d053/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f63366232336236353237626434303730393237363363616365333234656634612e737667)](https://www.codacy.com/app/vojtasvoboda/oc-twigextensions-plugin)[![Scrutinizer Coverage](https://camo.githubusercontent.com/c975d22114b47eb6703143d231ce00e58f42e6d823adf8f696b81f1bd8291c44/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f766f6a746173766f626f64612f6f632d74776967657874656e73696f6e732d706c7567696e2e737667)](https://scrutinizer-ci.com/g/vojtasvoboda/oc-twigextensions-plugin/?branch=master)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/vojtasvoboda/oc-twigextensions-plugin/blob/master/LICENSE)

Twig extensions plugin for OctoberCMS adds new filter and functions to your templates. No other plugin dependencies.

Tested with the latest stable OctoberCMS build 420 (with Laravel 5.5). For Laravel 5.4 use special branch `laravel54`.

Installation
------------

[](#installation)

Install plugin from CMS backend or by Composer:

```
composer require creative-sizzle/wn-twigextensions-plugin

```

Than you can use newly added filters/functions at your templates:

```
{{ article.heading | uppercase }}

	Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}

	{{ article.perex | truncate(80) }}

```

Available functions
-------------------

[](#available-functions)

[config](https://laravel.com/docs/5.0/configuration#accessing-configuration-values), [env](https://laravel.com/docs/5.8/helpers#method-env), [session](https://laravel.com/docs/5.0/session#session-usage), [trans](https://octobercms.com/docs/plugin/localization), [var\_dump](http://php.net/manual/en/function.var-dump.php), [template\_from\_string](http://twig.sensiolabs.org/doc/functions/template_from_string.html)

### config

[](#config)

Function move the functionality of the Laravel `config()` helper function to Twig.

```
{{ config('app.locale') }}

```

The example would output the value currently stored in `app.locale`. See [more about the Laravel config helper function here](https://laravel.com/docs/5.0/configuration#accessing-configuration-values).

### env

[](#env)

Function move the functionality of the Laravel `env()` helper function to Twig.

```
{{ env('APP_ENV', 'production') }}

```

The example would output the value currently stored in `APP_ENV` environment variable. Second parameter is default value, when ENV key does not exists.

### session

[](#session)

Function move the functionality of the Laravel `session()` helper function to Twig.

```
{{ session('my.session.key') }}

```

The example would output the value currently stored in `my.session.key`. See [more about the Laravel session helper function here](https://laravel.com/docs/5.0/session#session-usage).

### trans

[](#trans)

Function move the functionality of the Laravel `trans()` helper function to Twig.

```
{{ trans('acme.blog::lang.app.name') }}

```

The example would output a value stored in a localization file of an imaginary blog plugin. See [more about localization in October CMS here](https://octobercms.com/docs/plugin/localization).

### var\_dump

[](#var_dump)

Dumps information about a variable. Can be also used as filter.

```
{{ var_dump(users) }}

```

### template\_from\_string

[](#template_from_string)

Function loads a template from a string.

```
{% set name = 'John' %}
{{ include(template_from_string("Hello {{ name }}")) }}
{{ include(template_from_string("Hurry up it is: {{ "now"|date("m/d/Y") }}")) }}

```

Available filters
-----------------

[](#available-filters)

strftime, uppercase, lowercase, ucfirst, lcfirst, ltrim, rtrim, str\_repeat, plural, truncate, wordwrap, strpad, str\_replace, strip\_tags, leftpad, rightpad, rtl, shuffle, time\_diff, localizeddate, localizednumber, localizedcurrency, mailto, var\_dump, revision, sortbyfield

### strftime

[](#strftime)

Format a local time/date according to locale settings.

```
Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}

```

The example would output *Posted at 04.01.2016 22:57:42*. See [more format parameters](http://php.net/manual/en/function.strftime.php#refsect1-function.strftime-parameters).

### uppercase

[](#uppercase)

Make a string uppercase.

```
Hello I'm {{ 'Jack' | uppercase }}

```

The example would output *Hello I'm JACK*.

### lowercase

[](#lowercase)

Make a string lowercase.

```
Hello I'm {{ 'JACK' | lowercase }}

```

The example would output *Hello I'm jack*.

### ucfirst

[](#ucfirst)

Make a string's first character uppercase.

```
Hello I'm {{ 'jack' | ucfirst }}

```

The example would output *Hello I'm Jack*.

### lcfirst

[](#lcfirst)

Make a string's first character lowercase.

```
Hello I'm {{ 'Jack' | lcfirst }}

```

The example would output *Hello I'm jack*.

### ltrim

[](#ltrim)

Strip whitespace (or other characters) from the beginning of a string.

```
Hello I'm {{ ' jack' | ltrim }}

```

The example would output *Hello I'm jack* without whitespaces from the start.

### rtrim

[](#rtrim)

Strip whitespace (or other characters) from the end of a string.

```
Hello I'm {{ 'jack ' | rtrim }}

```

The example would output *Hello I'm jack* without whitespaces from the end.

### str\_repeat

[](#str_repeat)

Repeat a string.

```
I'm the {{ 'best' | str_repeat(3) }}!

```

The example would output *I'm the best best best!*

### plural

[](#plural)

Get the plural form of an English word.

```
You have {{ count }} new {{ 'mail' | plural(count) }}

```

The example would output *You have 1 new mail* or *You have 3 new mails* - depending on mails count.

### truncate

[](#truncate)

Use the truncate filter to cut off a string after limit is reached.

```
{{ "Hello World!" | truncate(5) }}

```

The example would output *Hello...*, as ... is the default separator.

You can also tell truncate to preserve whole words by setting the second parameter to true. If the last Word is on the the separator, truncate will print out the whole Word.

```
{{ "Hello World!" | truncate(7, true) }}

```

Here *Hello World!* would be printed.

If you want to change the separator, just set the third parameter to your desired separator.

```
{{ "Hello World!" | truncate(7, false, "??") }}

```

This example would print *Hello W??*.

### wordwrap

[](#wordwrap)

Use the wordwrap filter to split your text in lines with equal length.

```
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10) }}

```

This example would print:

```
Lorem ipsu
m dolor si
t amet, co
nsectetur
adipiscing

```

The default separator is "\\n", but you can easily change that by providing one:

```
{{ "Lorem ipsum dolor sit amet, consectetur adipiscing" | wordwrap(10, "zz\n") }}

```

This would result in:

```
Lorem ipsuzz
m dolor sizz
t amet, cozz
nsectetur zz
adipiscing

```

### strpad

[](#strpad)

Pad a string to a certain length with another string from both sides.

```
{{ 'xxx' | strpad(7, 'o') }}

```

This would print:

```
ooxxxoo

```

### str\_replace

[](#str_replace)

Replace all occurrences of the search string with the replacement string.

```
{{ 'Alice' | str_replace('Alice', 'Bob') }}

```

This would return:

```
Bob

```

### strip\_tags

[](#strip_tags)

Strip HTML and PHP tags from a string. In first parameter you can specify allowable tags.

```
{{ 'Text' | strip_tags('') }}

```

This would return:

```
Text

```

### leftpad

[](#leftpad)

Pad a string to a certain length with another string from left side.

```
{{ 'xxx' | leftpad(5, 'o') }}

```

This would print:

```
ooxxx

```

### rightpad

[](#rightpad)

Pad a string to a certain length with another string from right side.

```
{{ 'xxx' | rightpad(5, 'o') }}

```

This would print:

```
xxxoo

```

### rtl

[](#rtl)

Reverse a string.

```
{{ 'Hello world!' | rtl }}

```

This would print:

```
!dlrow olleH

```

### shuffle

[](#shuffle)

Shuffle an array.

```
{{ songs | shuffle }}

```

or in foreach:

```
{% for fruit in ['apple', 'banana', 'orange'] | shuffle %}
	{{ fruit }}
{% endfor %}

```

### time\_diff

[](#time_diff)

Use the time\_diff filter to render the difference between a date and now.

```
{{ post.published_at | time_diff }}

```

The example above will output a string like 4 seconds ago or in 1 month, depending on the filtered date.

Output is **translatable**. All translations are stored at `/lang` folder in this plugin. If you want more locales, just copy them from [this repository](https://github.com/KnpLabs/KnpTimeBundle/tree/master/Resources/translations), replace `%count%` with `:count` and send it as pull reqest to this repository.

#### Arguments

[](#arguments)

- date: The date for calculate the difference from now. Can be a string or a DateTime instance.
- now: The date that should be used as now. Can be a string or a DateTime instance. Do not set this argument to use current date.

#### Translation

[](#translation)

To get a translatable output, give a Symfony\\Component\\Translation\\TranslatorInterface as constructor argument. The returned string is formatted as diff.ago.XXX or diff.in.XXX where XXX can be any valid unit: second, minute, hour, day, month, year.

### localizeddate

[](#localizeddate)

Use the localizeddate filter to format dates into a localized string representating the date. Note that **php5-intl extension**/**php7-intl extension** has to be installed!

```
{{ post.published_at | localizeddate('medium', 'none', locale) }}

```

The localizeddate filter accepts strings (it must be in a format supported by the strtotime function), DateTime instances, or Unix timestamps.

#### Arguments

[](#arguments-1)

- date\_format: The date format. Choose one of these formats:
    - 'none': IntlDateFormatter::NONE
    - 'short': IntlDateFormatter::SHORT
    - 'medium': IntlDateFormatter::MEDIUM
    - 'long': IntlDateFormatter::LONG
    - 'full': IntlDateFormatter::FULL
- time\_format: The time format. Same formats possible as above.
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()
- timezone: The date timezone
- format: Optional pattern to use when formatting or parsing. Possible patterns are documented in the ICU user guide.

### localizednumber

[](#localizednumber)

Use the localizednumber filter to format numbers into a localized string representating the number. Note that **php5-intl extension** has to be installed!

```
{{ product.quantity | localizednumber }}

```

Internally, Twig uses the PHP NumberFormatter::create() function for the number.

#### Arguments

[](#arguments-2)

- style: Optional date format (default: 'decimal'). Choose one of these formats:
    - 'decimal': NumberFormatter::DECIMAL
    - 'currency': NumberFormatter::CURRENCY
    - 'percent': NumberFormatter::PERCENT
    - 'scientific': NumberFormatter::SCIENTIFIC
    - 'spellout': NumberFormatter::SPELLOUT
    - 'ordinal': NumberFormatter::ORDINAL
    - 'duration': NumberFormatter::DURATION
- type: Optional formatting type to use (default: 'default'). Choose one of these types:
    - 'default': NumberFormatter::TYPE\_DEFAULT
    - 'int32': NumberFormatter::TYPE\_INT32
    - 'int64': NumberFormatter::TYPE\_INT64
    - 'double': NumberFormatter::TYPE\_DOUBLE
    - 'currency': NumberFormatter::TYPE\_CURRENCY
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()

### localizedcurrency

[](#localizedcurrency)

Use the localizedcurrency filter to format a currency value into a localized string. Note that **php5-intl extension** has to be installed!

```
{{ product.price | localizedcurrency('EUR') }}

```

#### Arguments

[](#arguments-3)

- currency: The 3-letter ISO 4217 currency code indicating the currency to use.
- locale: The locale used for the format. If NULL is given, Twig will use Locale::getDefault()

### mailto

[](#mailto)

Filter for rendering email as normal mailto link, but with encryption against bots!

```
{{ 'vojtasvoboda.cz@gmail.com' | mailto }}

```

returns

```
[javascript protected email address]/**/

```

which will be rendered to page as normal

```
vojtasvoboda.cz@gmail.com

```

PHP encrypts your email address and generates the JavaScript that decrypts it. Most bots can't execute JavaScript and that is what makes this work. A visitors of your web page will not notice that you used this script as long as they has JavaScript enabled. The visitors will see "\[javascript protected email address\]" instead of the email address if they has JavaScript disabled.

#### Filter parameters

[](#filter-parameters)

```
{{ 'vojtasvoboda.cz@gmail.com' | mailto(true, true, 'Let me know', 'my-class') }}

```

- first boolean parameter = returns email clickable (with link)
- second boolean parameter = encryption is enabled
- third string parameter = link text (not encrypted!)
- fourth (optional) parameter = CSS class name (will render &lt;a mailto:.. class="my-class"&gt;..)

### var\_dump

[](#var_dump-1)

Dumps information about a variable.

```
{{ users | var_dump }}

```

### revision

[](#revision)

Force the browser to reload cached modified/updated asset files. You can provide a format parameter so that the prepended timestamp get converted accordingly to the PHP date() function.

#### usage

[](#usage)

```

```

Will return something like

```

```

See: [vojtasvoboda#25](https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/25)

### sortbyfield

[](#sortbyfield)

Sort array/collection by given field (key).

```
{% set data = [{'name': 'David', 'age': 31}, {'name': 'John', 'age': 28}] %}
{% for item in data | sortbyfield('age') %}
    {{ item.name }}&nbsp;
{% endfor %}

```

Output will be: John David

Contributing
------------

[](#contributing)

- Fix time\_diff unit test, which pass at local machine, but fails at TravisCI.
- Convert PHP functions and custom code to the Twig\_Extension classes.
- Create Twig\_Extension loader and load all extensions and filters as Twig\_Extension automatically from config.
- New filters *ga* and *gtm* for adding GA or GTM code (Heap Analytics) - {{ 'UA-1234567' | ga }}.
- Add [cache extension](https://github.com/vojtasvoboda/oc-twigextensions-plugin/issues/11).

**Feel free to send pullrequest!** Please, send Pull Request to master branch.

License
-------

[](#license)

Twig extensions plugin is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) same as OctoberCMS platform.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 83.8% 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 ~59 days

Recently: every ~156 days

Total

26

Last Release

2297d ago

PHP version history (2 changes)1.0.1PHP &gt;=5.4.0

1.2.0PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b19b55a9146f9ba3510a3aaf52a5ae051ef744ac7abad4e4d5532f2fce7271e4?d=identicon)[ericp-mrel](/maintainers/ericp-mrel)

---

Top Contributors

[![vojtasvoboda](https://avatars.githubusercontent.com/u/374917?v=4)](https://github.com/vojtasvoboda "vojtasvoboda (83 commits)")[![gergo85](https://avatars.githubusercontent.com/u/2959112?v=4)](https://github.com/gergo85 "gergo85 (4 commits)")[![ericp-mrel](https://avatars.githubusercontent.com/u/63664924?v=4)](https://github.com/ericp-mrel "ericp-mrel (3 commits)")[![emzet](https://avatars.githubusercontent.com/u/5151119?v=4)](https://github.com/emzet "emzet (2 commits)")[![FrontEndStudio](https://avatars.githubusercontent.com/u/749913?v=4)](https://github.com/FrontEndStudio "FrontEndStudio (1 commits)")[![jeanniton-mnr](https://avatars.githubusercontent.com/u/11714176?v=4)](https://github.com/jeanniton-mnr "jeanniton-mnr (1 commits)")[![ribsousa](https://avatars.githubusercontent.com/u/2750974?v=4)](https://github.com/ribsousa "ribsousa (1 commits)")[![evici](https://avatars.githubusercontent.com/u/44578107?v=4)](https://github.com/evici "evici (1 commits)")[![codebugs](https://avatars.githubusercontent.com/u/11911760?v=4)](https://github.com/codebugs "codebugs (1 commits)")[![der-On](https://avatars.githubusercontent.com/u/359399?v=4)](https://github.com/der-On "der-On (1 commits)")[![aurelien-roy](https://avatars.githubusercontent.com/u/1875998?v=4)](https://github.com/aurelien-roy "aurelien-roy (1 commits)")

---

Tags

wintercms-plugintwiglowercaseuppercaseextensionstruncatewordwraptime diffstrftimeleftpad

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/creative-sizzle-wn-twigextensions-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/creative-sizzle-wn-twigextensions-plugin/health.svg)](https://phpackages.com/packages/creative-sizzle-wn-twigextensions-plugin)
```

###  Alternatives

[craue/twigextensions-bundle

Useful Twig extensions for your Symfony project.

81212.3k1](/packages/craue-twigextensions-bundle)[dzango/twig-truncate-extension

A Twig extension to truncate text while preserving HTML tags

13238.9k2](/packages/dzango-twig-truncate-extension)[vojtasvoboda/oc-twigextensions-plugin

Register more Twig filters for your OctoberCMS templates

198.4k1](/packages/vojtasvoboda-oc-twigextensions-plugin)[dms/twig-extension-bundle

DMS Twig Extension Bundle, leverages Fabien Potencier's extra twig extensions for your website.

19296.3k](/packages/dms-twig-extension-bundle)[bluetel-solutions/twig-truncate-extension

Twig Extension to truncate nested HTML, safely!

11100.0k](/packages/bluetel-solutions-twig-truncate-extension)[yepsua/smartwig-bundle

The jQuery, jQueryUI (and more) Symfony Bundle

214.0k1](/packages/yepsua-smartwig-bundle)

PHPackages © 2026

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