Airship\Engine\Lens::filter PHP Method

filter() public method

Add a filter to Twig
public filter ( string $name, callable $func = null ) : self
$name string - Name to access n Twig
$func callable - function to apply
return self
    public function filter(string $name, $func = null) : self
    {
        if (empty($func)) {
            $func = '\\Airship\\LensFunctions\\' . $name;
        }
        $this->twigEnv->addFilter(new \Twig_SimpleFilter($name, $func));
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Add a filter to the lens
  *
  * @param string $name
  * @param callable $func
  */
 protected function addLensFilter(string $name, callable $func)
 {
     $this->airship_lens_object->filter($name, $func);
 }