TwigExtensions by justb3a

Allows customizing twig, e.g. add extensions

WARNING: This repository is no longer maintained

This repository will not be updated. The repository will be kept available in read-only mode.

ProcessWire Twig Extensions

Allows customizing twig, e.g. add extensions.

Dependencies:

Instructions:

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

Includes:

Twig Extensions Repository

Usage:

Adds the following extensions/helpers:

Extensions


  • 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') }}
    50.556
    
    {# localizedcurrency - format a currency value into a localized string #}
    {{ '50.5555'|localizedcurrency('EUR', 'en') }}
    €50.56
  • Text

    {# truncate - cut off a string after limit is reached #}
    {{ 'Hello World!'|truncate(5) }}
    Hello...
    
    {# wordwrap - split your text in lines with equal length #}
    {{ 'Hello World!'|wordwrap(4) }}
    Hell
    o Wo
    rld!
  • 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

Helpers


  • 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'

Features


  • kalongFeature: A frontend styleguide development toolkit
    • Kalong is a collection/combination of different tools, to help you get started creating your own frontend styleguide, with easy reusable components
    • it is based on Fractal and a collection of custom gulp-tasks to get you started fast

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #519
    In the 519th issue of ProcessWire Weekly we'll check out a new third party module called RockForms, introduce the latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 20 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer