Only

The only filter returns only the items whose keys match those supplied arguments (space separated) based on a case-insensitive search.

You could use the excludes filter to achieve the same effect but you should use whichever filter requires you to pass in the least number of arguments.

Including the extension

You will need to include the Array extension in your view bootstrap and pass it to the Twig environment.

use Jadu\Pulsar\Twig\Extension\ArrayExtension;

$twig = new Twig_Environment(...);

$twig->addExtension(new ArrayExtension());

Example usage

{% 
    set input = {
        'foo': 'fighters', 
        'bar': 'enakedladies', 
        'baz': 'luhrmann'
    } 
%}

{% set output = input|only('foo') %}

Ouput:

{
    'foo': 'fighters'
}

Pass multiple items as a space separate string, eg: input|only('foo baz')

results matching ""

    No results matching ""