marcj/twig-apply_filter-bundle

Dynamic twig filter calls

0.1.0 2013-12-12 13:45 UTC

This package is auto-updated.

Last update: 2024-11-11 00:39:36 UTC


README

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