Symfony Bundle for Twig 'apply_filter' to call dynamic filters.
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DependencyInjection
Resources/config
Tests
Twig
.travis.yml
MJSTwigApplyFilterBundle.php
README.md
composer.json
phpunit.xml.dist

README.md

Twig apply_filter

This filter allows you to call dynamic filters in twig.

Build Status

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(),
    );
}

Bitdeli Badge