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 State | Stable Should be safe for use in production environments. * |
Author | |
Module Version | 1.0.3 |
Class Name | TwigExtensions |
Compatibility | 3.0 |
Date Added | March 10, 2017 |
Last Updated | May 17, 2017 |
Recommended By | New recommendations may take up to 1 day to appear. |
Instructions
This module's files should be placed in /site/modules/TwigExtensions/
How to install or uninstall modules
README
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:
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!"
{# 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
{# 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!
{# shuffle - randomize an array #} {{ [ 'one', 'two', 'three', 'four' ]|shuffle }} [ 'two', 'three', 'one', 'four' ]
{# 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'
Comments
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.
- Admin Helpers
- Core Modules
- Development Tools
- Field Types
- File Validator
- Import/Export
- Input Fields
- Language Modules
- Language Packs
- Logs/Monitoring
- Markup Generation
- Photo/Video/Audio
- Premium Modules
- Process Modules
- Proof of Concept
- SEO/Accessibility
- Site Profiles
- Social, Feeds, Services
- Text Formatters
- Other Modules
- Users and Access
Disclaimer
*Use modules at your own risk. There are no guarantees or warranties. It is recommended that you backup your site and database before installing new modules.