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

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

rezgui/twigextensions-plugin
============================

Register more Twig filters for your WinterCMS templates

02PHP

Since Mar 28Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#twig-extensions)

[![GitHub forks](https://camo.githubusercontent.com/fcca25446d2b8f95b0db65d9797a5c5aed0f61a840e7c139f8a0ea9408c10771/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f766f6a746173766f626f64612f6f632d74776967657874656e73696f6e732d706c7567696e3f7374796c653d666c6174)](https://camo.githubusercontent.com/fcca25446d2b8f95b0db65d9797a5c5aed0f61a840e7c139f8a0ea9408c10771/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f766f6a746173766f626f64612f6f632d74776967657874656e73696f6e732d706c7567696e3f7374796c653d666c6174)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/vojtasvoboda/oc-twigextensions-plugin/blob/master/LICENSE)

Twig extensions forked from [vojtasvoboda/oc-twigextensions-plugin](https://github.com/vojtasvoboda/oc-twigextensions-plugin), is a plugin for WinterCMS adds new filter and functions to your templates. No other plugin dependencies.

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

[](#installation)

Install plugin from CMS backend or by Composer:

```
composer require rezgui/wn-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://wintercms.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 Winter CMS here](https://wintercms.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: [vojtasvoboda#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.

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

16

—

LowBetter than 5% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 86.7% 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.

### Community

Maintainers

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

---

Top Contributors

[![vojtasvoboda](https://avatars.githubusercontent.com/u/374917?v=4)](https://github.com/vojtasvoboda "vojtasvoboda (111 commits)")[![rezgui](https://avatars.githubusercontent.com/u/1289096?v=4)](https://github.com/rezgui "rezgui (4 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)")[![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)")[![evici](https://avatars.githubusercontent.com/u/44578107?v=4)](https://github.com/evici "evici (1 commits)")

### Embed Badge

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

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

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

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