marcj / twig-apply_filter-bundle
Dynamic twig filter calls
Installs: 10 695
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 2
Requires (Dev)
- twig/twig: ~1.0
This package is auto-updated.
Last update: 2024-12-11 00:53:39 UTC
README
This filter allows you to call dynamic filters in twig.
Examples
{{ set filters = 'upper|nl2br' }} {{ value|apply_filter(filters) }} {{ value|apply_filter("default('abc')|json_encode") }}
A filter for e.g. a News system, where the title filter is stored in the database:
{% for item in newsItems %} <h2>{{ item.title|apply_filter(databaseSettings.newsFilter) }}</h2> {% endfor %}
Installation
Install via composer
composer.phar require marcj/twig-apply_filter-bundle
Activate bundle
Open your AppKernel.php
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new MJS\TwigApplyFilter\MJSTwigApplyFilterBundle(), ); }