I am currently using twig standalone (not with symphony or composer) and am not finding in the documentation on how to register an extension in php.
My index.php file looks like this
<?php
include 'exts/ext.php';
require_once 'Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_Environment($loader);
$twig->addExtension(new Test_Twig_Extension())
echo $twig->render('index.twig');
?>
My extension class looks like this (ext.php)
<?php
//require_once 'Twig/Extension.php';
//require_once 'Twig/ExtensionInterface.php';
class Test_Twig_Extension extends Twig_Extension {
public function getFunctions() {
return array(
new Twig_SimpleFunction('my_function', array($this,'my_function'))
);
}
public function my_function($arg1, $arg2) {
echo "Arg1: {$arg1} and Arg2: {$arg2}";
}
public function getName(){
return 'my_function';
}
}
?>
I get the following error:
Fatal error: Interface 'Twig_ExtensionInterface' not found in C:\xampp\htdocs\Twig\Extension.php on line 12
I have found tones of articles with setting it up with yaml but I am not using yaml.
I am sure I am not registering this properly or do not have something set up just right.