https://github.com/philecms/philetwigfilters
An example plugin showing how to make Twig filters.
https://github.com/philecms/philetwigfilters
philecms-plugin
Last synced: 7 months ago
JSON representation
An example plugin showing how to make Twig filters.
- Host: GitHub
- URL: https://github.com/philecms/philetwigfilters
- Owner: PhileCMS
- License: mit
- Created: 2013-11-02T01:21:58.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2018-03-29T15:41:23.000Z (about 8 years ago)
- Last Synced: 2024-12-28T02:48:49.473Z (over 1 year ago)
- Topics: philecms-plugin
- Language: PHP
- Size: 15.6 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Twig Functions
[](https://travis-ci.org/PhileCMS/phileTwigFilters)
Adds helpfull Twig functions to [Phile](https://github.com/PhileCMS/Phile) and easily allows you to create new ones. [Project home](https://github.com/PhileCMS/phileTwigFilters).
## Installation
```bash
composer require phile/twig-functions
```
## Activation
```php
$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.
```twig
{{ content|excerpt }}
```
### limit_words
Similar to `excert` but limits on number of words. Use Twig's `striptags` to remove HTML-tags.
```twig
{{ page.content|striptags|limit_words }}
```
### shuffle
Shuffles an array. For example show a shuffled lists of pages:
```twig
- {{ page.title }}
{% for page in pages|shuffle %}
{% endfor %}
```
### 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.
```twig
{{ "This Is ____an STRÄNGE string" | slugify }}
```