addTwigFunction

The method $this->addTwigFunction($name, $function) adds a function to Twig.

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

Example Usage

<?php

namespace Plugins\Myplugin;

use \Typemill\Plugin;

class Myplugin extends Plugin
{
    ...

    public function myFunction()
    {
       $this->addTwigFunction('myName', function(){
          return 'My name is ';
       });
    }
}

Use it in your twig-template like this:

{{ myName() }}

Read the Twig-Documentation for more details.