PHPackages                             vojtasvoboda/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. vojtasvoboda/twigextensions-plugin

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

vojtasvoboda/twigextensions-plugin
==================================

Register more Twig filters for your OctoberCMS templates

2.0.7(9mo ago)1920↓50%29[2 PRs](https://github.com/vojtasvoboda/oc-twigextensions-plugin/pulls)MITPHPPHP &gt;=8.0.2

Since Jan 4Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/vojtasvoboda/oc-twigextensions-plugin)[ Packagist](https://packagist.org/packages/vojtasvoboda/twigextensions-plugin)[ RSS](/packages/vojtasvoboda-twigextensions-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (40)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 3.1.18 on PHP 8.0.

Versions
--------

[](#versions)

October 1.0.x, 1.1.x or 2.x.x - use special [branch 1.x](https://github.com/vojtasvoboda/oc-twigextensions-plugin/tree/1.x)October 3.1+ or 4.x - use master branch For old Laravel 5.4 October's versions - use special branch `laravel54`

For migrating between plugin's version 1 and version 2 you can use special [UPGRADE.md](UPGRADE.md) guide.

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

[](#installation)

Install plugin from CMS backend or by Composer:

```
composer require vojtasvoboda/oc-twigextensions-plugin

```

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

```
{{ article.heading | ltrim }}

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

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

```

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

[](#available-functions)

[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](https://twig.symfony.com/doc/3.x/functions/template_from_string.html), [country\_timezones](https://twig.symfony.com/doc/3.x/functions/country_timezones.html)

### session

[](#session)

Function moves 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).

You can also use OctoberCMS function: `{{ this.session.get('my.session.key') }}`, but it's little bit longer :-)

### trans

[](#trans)

Function moves 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).

You can also use trans filter: `{{ 'acme.blog::lang.app.name'|trans }}`.

### var\_dump

[](#var_dump)

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

```
{{ var_dump(users) }}

```

You can also use {{ dump(users) }} function to dump information about a variable. Properties are "clickable" to expand.

### 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") }}")) }}

```

### country\_timezones

[](#country_timezones)

The country\_timezones function returns the names of the timezones associated with a given country code:

```
{# Europe/Paris #}
{{ country_timezones('FR')|join(', ') }}
```

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

[](#available-filters)

- PHP functions: strftime, ltrim, rtrim, var\_dump, wordwrap
- custom functions: revision
- internationalized names filters: country\_name, currency\_name, currency\_symbol, language\_name, locale\_name, timezone\_name
- localized formatters filters: format\_currency, format\_number, format\_\*\_number, format\_datetime, format\_date, format\_time

### 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).

You can also use `{{ carbon(article.date).formatLocalized('%d.%m.%Y %H:%M:%S') }}`.

### 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.

You can also use `{{ '  I like Twig.  '|trim(side='left') }}` native Twig filter.

### 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.

You can also use `{{ '  I like Twig.  '|trim(side='right') }}` native Twig filter.

### var\_dump

[](#var_dump-1)

Dumps information about a variable.

```
{{ users | var_dump }}

```

You can also use `{{ var_dump(users) }}` or `{{ dump(users) }}` functions.

### wordwrap

[](#wordwrap)

Use the wordwrap filter to split your text into 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

```

### revision

[](#revision)

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

#### usage

[](#usage)

```

```

Will return something like

```

```

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

### country\_name

[](#country_name)

The country\_name filter returns the country name given its ISO-3166 two-letter code:

```
{# France #}
{{ 'FR'|country_name }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# États-Unis #}
{{ 'US'|country_name('fr') }}
```

### currency\_name

[](#currency_name)

The currency\_name filter returns the currency name given its three-letter code:

```
{# Euro #}
{{ 'EUR'|currency_name }}

{# Japanese Yen #}
{{ 'JPY'|currency_name }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# yen japonais #}
{{ 'JPY'|currency_name('fr_FR') }}
```

### currency\_symbol

[](#currency_symbol)

The currency\_symbol filter returns the currency symbol given its three-letter code:

```
{# € #}
{{ 'EUR'|currency_symbol }}

{# ¥ #}
{{ 'JPY'|currency_symbol }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# ¥ #}
{{ 'JPY'|currency_symbol('fr') }}
```

### language\_name

[](#language_name)

The language\_name filter returns the language name given its two-letter code:

```
{# German #}
{{ 'de'|language_name }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# allemand #}
{{ 'de'|language_name('fr') }}

{# français canadien #}
{{ 'fr_CA'|language_name('fr_FR') }}
```

### locale\_name

[](#locale_name)

The locale\_name filter returns the locale name given its two-letter code:

```
{# German #}
{{ 'de'|locale_name }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# allemand #}
{{ 'de'|locale_name('fr') }}

{# français (Canada) #}
{{ 'fr_CA'|locale_name('fr_FR') }}
```

### timezone\_name

[](#timezone_name)

The timezone\_name filter returns the timezone name given a timezone identifier:

```
{# Central European Time (Paris) #}
{{ 'Europe/Paris'|timezone_name }}

{# Pacific Time (Los Angeles) #}
{{ 'America/Los_Angeles'|timezone_name }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# heure du Pacifique nord-américain (Los Angeles) #}
{{ 'America/Los_Angeles'|timezone_name('fr') }}
```

### format\_currency

[](#format_currency)

The format\_currency filter formats a number as a currency:

```
{# €1,000,000.00 #}
{{ '1000000'|format_currency('EUR') }}
```

You can pass attributes to tweak the output:

```
{# €12.34 #}
{{ '12.345'|format_currency('EUR', {rounding_mode: 'floor'}) }}

{# €1,000,000.0000 #}
{{ '1000000'|format_currency('EUR', {fraction_digit: 4}) }}
```

The list of supported options:

- grouping\_used;
- decimal\_always\_shown;
- max\_integer\_digit;
- min\_integer\_digit;
- integer\_digit;
- max\_fraction\_digit;
- min\_fraction\_digit;
- fraction\_digit;
- multiplier;
- grouping\_size;
- rounding\_mode;
- rounding\_increment;
- format\_width;
- padding\_position;
- secondary\_grouping\_size;
- significant\_digits\_used;
- min\_significant\_digits\_used;
- max\_significant\_digits\_used;
- lenient\_parse.

By default, the filter uses the current locale. You can pass it explicitly:

```
{# 1.000.000,00 € #}
{{ '1000000'|format_currency('EUR', locale='de') }}
```

### format\_number and format\_\*\_number

[](#format_number-and-format__number)

The format\_number filter formats a number:

```
{{ '12.345'|format_number }}
```

You can pass attributes to tweak the output:

```
{# 12.34 #}
{{ '12.345'|format_number({rounding_mode: 'floor'}) }}

{# 1000000.0000 #}
{{ '1000000'|format_number({fraction_digit: 4}) }}
```

The list of supported options:

- grouping\_used;
- decimal\_always\_shown;
- max\_integer\_digit;
- min\_integer\_digit;
- integer\_digit;
- max\_fraction\_digit;
- min\_fraction\_digit;
- fraction\_digit;
- multiplier;
- grouping\_size;
- rounding\_mode;
- rounding\_increment;
- format\_width;
- padding\_position;
- secondary\_grouping\_size;
- significant\_digits\_used;
- min\_significant\_digits\_used;
- max\_significant\_digits\_used;
- lenient\_parse.

Besides plain numbers, the filter can also format numbers in various styles:

```
{# 1,234% #}
{{ '12.345'|format_number(style='percent') }}

{# twelve point three four five #}
{{ '12.345'|format_number(style='spellout') }}

{# 12 sec. #}
{{ '12'|format_duration_number }}
```

The list of supported styles:

- decimal;
- currency;
- percent;
- scientific;
- spellout;
- ordinal;
- duration.

As a shortcut, you can use the format\_\*\_number filters by replacing `*` with a style:

```
{# 1,234% #}
{{ '12.345'|format_percent_number }}

{# twelve point three four five #}
{{ '12.345'|format_spellout_number }}
```

You can pass attributes to tweak the output:

```
{# 12.3% #}
{{ '0.12345'|format_percent_number({rounding_mode: 'floor', fraction_digit: 1}) }}
```

By default, the filter uses the current locale. You can pass it explicitly:

```
{# 12,345 #}
{{ '12.345'|format_number(locale='fr') }}
```

### format\_datetime

[](#format_datetime)

The format\_datetime filter formats a date time:

```
{# Aug 7, 2019, 11:39:12 PM #}
{{ '2019-08-07 23:39:12'|format_datetime() }}
```

#### Format

[](#format)

You can tweak the output for the date part and the time part:

```
{# 23:39 #}
{{ '2019-08-07 23:39:12'|format_datetime('none', 'short', locale='fr') }}

{# 07/08/2019 #}
{{ '2019-08-07 23:39:12'|format_datetime('short', 'none', locale='fr') }}

{# mercredi 7 août 2019 23:39:12 UTC #}
{{ '2019-08-07 23:39:12'|format_datetime('full', 'full', locale='fr') }}
```

Supported values are: none, short, medium, long, and full.

For greater flexibility, you can even define your own pattern (see the ICU user guide for supported patterns).

```
{# 11 oclock PM, GMT #}
{{ '2019-08-07 23:39:12'|format_datetime(pattern="hh 'oclock' a, zzzz") }}
```

#### Locale

[](#locale)

By default, the filter uses the current locale. You can pass it explicitly:

```
{# 7 août 2019 23:39:12 #}
{{ '2019-08-07 23:39:12'|format_datetime(locale='fr') }}
```

#### Timezone

[](#timezone)

By default, the date is displayed by applying the default timezone (the one specified in php.ini or declared in Twig -- see below), but you can override it by explicitly specifying a timezone:

```
{{ datetime|format_datetime(locale='en', timezone='Pacific/Midway') }}
```

If the date is already a DateTime object, and if you want to keep its current timezone, pass false as the timezone value:

```
{{ datetime|format_datetime(locale='en', timezone=false) }}
```

The default timezone can also be set globally by calling setTimezone():

```
$twig = new \Twig\Environment($loader);
$twig->getExtension(\Twig\Extension\CoreExtension::class)->setTimezone('Europe/Paris');

```

### format\_date

[](#format_date)

The format\_date filter formats a date. It behaves in the exact same way as the format\_datetime filter, but without the time.

### format\_time

[](#format_time)

The format\_time filter formats a time. It behaves in the exact same way as the format\_datetime filter, but without the date.

Removed functions
-----------------

[](#removed-functions)

Functions used in plugin's version 1.x for October 1.0.x, 1.1.x, 2.0.x and removed from this version:

- config() - it's native function since October 3.1.17
- env() - it's native function since October 3.1.17

Removed filters
---------------

[](#removed-filters)

Filters used in plugin's version 1.x for October 1.0.x, 1.1.x, 2.0.x and removed from this version:

- uppercase - use str\_upper or just upper
- lowercase - use str\_lower or just lower
- ucfirst - use str\_ucfirst
- lcfirst - use str\_lcfirst
- str\_repeat - it's native filter now
- plural - use str\_plural
- truncate - use str\_limit
- strpad - use str\_pad\_both
- str\_replace - it's native filter now
- strip\_tags - use html\_strip
- leftpad - use str\_pad\_left
- rightpad - use str\_pad\_right
- rtl - use str\_reverse
- shuffle - use `collect(songs).shuffle()`
- time\_diff - use `carbon(post.published_at).diffForHumans()`
- localizeddate - use format\_date
- localizednumber - use format\_number
- localizedcurrency - use format\_currency
- mailto - use html\_mailto
- var\_dump - use dump function
- sortbyfield - use `collect(data).sortBy('age')` or `collect(data).sortByDesc('age')`

For more info see [UPGRADE.md](UPGRADE.md) guide.

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

[](#contributing)

- Make template\_from\_string turned off by default and add special checkbox to the backend to allow it.
- Add missing unit tests.
- 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

48

—

FairBetter than 94% of packages

Maintenance58

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 90.4% 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 ~94 days

Recently: every ~246 days

Total

38

Last Release

273d ago

Major Versions

1.x-dev → 2.0.02022-10-27

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

1.2.0PHP &gt;=7.0

1.3PHP &gt;=7.0.8

2.0.0PHP &gt;=8.0.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/533ab9a0897c6c6754ac9baf2ad6e42ecbc2a57aa67c72b885fcc647c7ae6930?d=identicon)[VojtaSvoboda](/maintainers/VojtaSvoboda)

---

Top Contributors

[![vojtasvoboda](https://avatars.githubusercontent.com/u/374917?v=4)](https://github.com/vojtasvoboda "vojtasvoboda (122 commits)")[![gergo85](https://avatars.githubusercontent.com/u/2959112?v=4)](https://github.com/gergo85 "gergo85 (4 commits)")[![emzet](https://avatars.githubusercontent.com/u/5151119?v=4)](https://github.com/emzet "emzet (2 commits)")[![evici](https://avatars.githubusercontent.com/u/44578107?v=4)](https://github.com/evici "evici (1 commits)")[![aurelien-roy](https://avatars.githubusercontent.com/u/1875998?v=4)](https://github.com/aurelien-roy "aurelien-roy (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)")[![FrontEndStudio](https://avatars.githubusercontent.com/u/749913?v=4)](https://github.com/FrontEndStudio "FrontEndStudio (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)")

---

Tags

octobercms-plugintwigtwig-extensiontwigextensions

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/vojtasvoboda-twigextensions-plugin/health.svg)

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

###  Alternatives

[craue/twigextensions-bundle

Useful Twig extensions for your Symfony project.

81212.3k1](/packages/craue-twigextensions-bundle)[vojtasvoboda/oc-twigextensions-plugin

Register more Twig filters for your OctoberCMS templates

198.4k1](/packages/vojtasvoboda-oc-twigextensions-plugin)[yepsua/smartwig-bundle

The jQuery, jQueryUI (and more) Symfony Bundle

214.0k3](/packages/yepsua-smartwig-bundle)[wanze/template-engine-twig

ProcessWire module adding Twig to the TemplateEngineFactory

128.1k](/packages/wanze-template-engine-twig)[tommcdo/kohana-twig

Kohana 3.3 module for the popular Twig template engine

241.9k](/packages/tommcdo-kohana-twig)[frozzare/digster

Twig templates for WordPress

107.1k](/packages/frozzare-digster)

PHPackages © 2026

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