About Twig Extensions

Allows customizing twig, e.g. add extensions

Category Markup Generation
Markup modules that are called upon to generate or parse markup (like HTML). Markup modules are most often used on the front-end of a site (rather than admin).
Release StateStable
Should be safe for use in production environments. *
Module Version1.0.3
Class NameTwigExtensions
Date AddedMarch 10, 2017
Last UpdatedMay 17, 2017
Recommended ByNew recommendations may take up to 1 day to appear.


This module's files should be placed in /site/modules/TwigExtensions/
How to install or uninstall modules


ProcessWire Twig Extensions

Allows customizing twig, e.g. add extensions.



After installation go to module settings and enable/disable the required extensions/functions.


Twig Extensions Repository


Adds the following extensions/helpers:


  • Debug // only if debug mode is turned on

    {# dump - dumps information about a template variable #}
    {{ dump('Hello World!') }}
    string(12) "Hello World!"
  • Intl

    {# localizeddate - format dates into a localized string representating the date #}
    {{ "now"|date_modify("-2 day")|localizeddate('medium', 'none', 'en') }}
    Mar 8, 2017
    {# localizednumber - format numbers into a localized string representating the number #}
    {{ '50.5555'|localizednumber('decimal', 'default', 'en') }}
    {# localizedcurrency - format a currency value into a localized string #}
    {{ '50.5555'|localizedcurrency('EUR', 'en') }}
  • Text

    {# truncate - cut off a string after limit is reached #}
    {{ 'Hello World!'|truncate(5) }}
    {# wordwrap - split your text in lines with equal length #}
    {{ 'Hello World!'|wordwrap(4) }}
    o Wo
  • Array

    {# shuffle - randomize an array #}
    {{ [ 'one', 'two', 'three', 'four' ]|shuffle }}
    [ 'two', 'three', 'one', 'four' ]
  • Date

    {# time_diff - difference between two dates #}
    {% set start = "now"|date_modify("-2 day") %}
    {% set end = "now"|date_modify("+2 day") %}
    {{ start|time_diff }}
    2 days ago
    {{ start|time_diff(end) }}
    4 days ago


  • fileExists: Checks whether a file or directory exists.

    {% if file_exists(config.paths.assets ~ 'img/filename.png') %}
      The file exists.
    {% else %}
      The file does not exist.
    {% endif %}
  • widont: Prevent widow in string

    • in typesetting a widow is a very short line (one word or the end of an hyphenated word),which is separated from the rest of the paragraph. It's considered as poor typography because it leaves too much white space.
    {{ 'Add Widont Helper'|widont }}
    'Add Widont Helper'


No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.