Twig Extensions

Recommended Posts

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/functions:

  • 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
  • Like 4

Share this post

Link to post
Share on other sites

@justb3a, I see you are extra busy today releasing new modules.  Great work!

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By BitPoet
      So I stumbled over the request to allow limiting templates to be used only once under every parent page in this thread
      and found that this would actually come in handy (also in a site I've built).
      The code can be found on github and soon in the module repo.
      After installation, you'll find a new checkbox "Only once per parent" in the family tab when editing a template.

    • By Robin S
      Password Generator
      Adds a password generator to InputfieldPassword.

      Install the Password Generator module.
      Now any InputfieldPassword has a password generation feature. The settings for the generator are taken automatically from the settings* of the password field.
      *Settings not supported by the generator:
      Complexify: but generated passwords should still satisfy complexify settings in the recommended range. Banned words: but the generated passwords are random strings so actual words are unlikely to occur.  
    • By Robin S
      If you've ever needed to insert links to a large number of files within CKEditor you may have found that the standard PW link modal is a somewhat slow way to do it.
      This module provides a quicker way to insert links to files on the page being edited. You can insert a link to an individual file, or insert an unordered list of links to all files on the page with a single click.
      CKEditor Link Files
      Adds a menu to CKEditor to allow the quick insertion of links to files on the page being edited.

      Hover a menu item to see the "Description" of the corresponding file (if present). Click a menu item to insert a link to the corresponding file at the current cursor position. The filename is used as the link text. If you Alt-click a menu item the file description is used as the link text (with fallback to filename if no description entered). If text is currently selected in the editor then the selected text is used as the link text. Click "* Insert links to all files *" to insert an unordered list of links to all files on the page. Also works with the Alt-click option. Menu is built via AJAX so newly uploaded files are included in the menu without the page needing to be saved. However, descriptions are not available for newly uploaded files until the page is saved. Installation
      Install the CKEditor Link Files module.
      For any CKEditor field where you want the "Insert link to file" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "LinkFilesMenu" to the "CKEditor Toolbar" settings field.
    • By matjazp
      A module for managing files and folders. Supports creating, opening (e.g. viewing, playing, editing), renaming, moving, copying, deleting and searching for files. You can also view and change (not supported on Windows) file and directory permissions. 

      The author of FileManager component is (c) 2006 - 2018 Gerd Tentler, http://www.gerd-tentler.de/tools/filemanager/. I modified it to work with ProcessWire as a module. Please see license files on usage in commercial projects!
    • By Robin S
      An inputfield for displaying markup editable via CKEditor.
      The module is intended for use with the Form Builder module. Allows blocks of static text to be included within a form, which can be edited in the form settings using CKEditor.
      Install the Markup CKEditor module.
      In the Form Builder module settings, add "MarkupCKEditor" to "Inputfield types to use with FormBuilder".
      In your form settings, add a new field of type "Markup CKEditor". Enter the text you want to show in this field using "Markup Text" on the "Details" tab.