marcj / twig-apply_filter-bundle
Dynamic twig filter calls
0.1.0
2013-12-12 13:45 UTC
Requires (Dev)
- twig/twig: ~1.0
This package is auto-updated.
Last update: 2026-03-11 03:31:41 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(), ); }