Airship\Engine\Lens::func PHP Method

func() public method

Add a function to our Twig environment
public func ( string $name, callable $func = null, array $is_safe = ['html'] ) : self
$name string - Name to access in Twig
$func callable - function definition
$is_safe array
return self
    public function func(string $name, $func = null, $is_safe = ['html']) : self
    {
        if (empty($func)) {
            $func = '\\Airship\\LensFunctions\\' . $name;
        }
        $this->twigEnv->addFunction(new \Twig_SimpleFunction($name, $func, ['is_safe' => $is_safe]));
        return $this;
    }

Usage Example

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