Thoughts from a developer//entrepreneur.
Founder of


php|Propel1 php|Propel2 php|CDS php|PHP-PM php|php-pm-httpkernel web| web|css-element-queries js|jQuery-selectBox php|PropelBundle php|Propel Sandbox js|angular2-localStorage js|angular-es6-annotations php|php-rest-service php|topsort.php xxx|BetterQuitJobBundle js|angular-typescript-decorators c++|node-core-audio php|optimistic-locking-behavior php|change-logger-behavior RSS

Twig dynamic filters / from variable.

12 December 2013, by Marc

In Twig it’s not possible to call filters based on a variable per default. I’ve created therefore a small Symfony bundle that provides a new Twig filter apply_filter which does exactly that: Calls filter based on a variable. Useful when you want to give your users a way to format something and therefore the filters comes from the database.


You can download and install this Twig apply_filter extension here:

Or via packagist:


{{ 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 %}