addTwigFilter

The method $this->addTwigFilter($name, $filter) adds a filter to Twig.

  • @param: (string) $name. The name of the filter.
  • @param: (\Twig\TwigFilter) $filter. The filter to add.

Example Usage

<?php

namespace Plugins\Myplugin;

use \Typemill\Plugin;

class Myplugin extends Plugin
{
    ...

    public function myFunction()
    {
        $this->addTwigFilter('rot13', function($string){
            return str_rot13($string);
        });
    }
}

Use it in your template like this:

{{ rot13('this is a text') }}

Read the Twig-Documentation for more details.