phile / twig-filters
An example plugin for Phile showing how to make Twig filters.
Installs: 66
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 0
Type:phile-plugin
Requires
- phile-cms/phile: ^1.0
- phile-cms/plugin-installer-plugin: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-10-29 04:30:53 UTC
README
Adds helpfull Twig functions to Phile and easily allows you to create new ones. Project home.
Installation
composer require phile/twig-functions
Activation
$config['plugins']['phile\\twigFunctions'] = [ 'active' => true ];
Usage
This plugin includes some predefined Twig-filter and allows you to easily add your own.
Define a New Custom Filter
See the existing filters in config.php for how to add your own filter.
excerpt
Grabs the first paragraph of the content string.
{{ content|excerpt }}
limit_words
Similar to excert
but limits on number of words. Use Twig's striptags
to remove HTML-tags.
{{ page.content|striptags|limit_words }}
shuffle
Shuffles an array. For example show a shuffled lists of pages:
<ul class="posts"> {% for page in pages|shuffle %} <li><a href="{{ page.url }}">{{ page.title }}</a></li> {% endfor %} </ul>
slugify
This new Twig filter allows you to slugify a string. This is useful for making safe URLs, HTML-safe class/id names, or just cleaning up general strings.
<!-- becomes "this–is–an–strange–string" --> {{ "This Is ____an STRÄNGE string" | slugify }}