I know, I know....
I really like the way the Twig templating engine works. I tried to hack up a module (messy, with hard coded paths etc. just to test) but I'm somewhat out of my depth.
I tried to make a module that had a before-render hook with this:
require_once '/path/to/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('/path/to/templates');
(with paths adjusted of course)
and a property hook (Page::twig) that returns the twig object below
$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
This is all taken from http://twig.sensiolabs.org/doc/api.html
I started to get odd errors from within the Twig files themselves and got lost trying to debug.
Has anyone succeeded in getting a module to load Twig? What I would like to do is have the .php files in the templates directory initialise variables etc required and then twig load (from a 'views' folder) the twig template associated with the PW template. I know this goes against the PW idea of using PHP as a templating engine in itself, but I would really love to be able to use Twig for an upcoming project and I know others have asked about similar functionalities with Twig and other templating engines. Perhaps someone more knowledgeable than myself can point me in the right direction to get such a monstrosity of crossbreeding working?
Slightly off topic: I tried to do the right thing and use the $config->urls... variables, but kept getting errors loading the Twig php files (even though the errors showed the correct paths). This is why I just started to use things like the __DIR__ variables for first tests, but even then I was having troubles. Perhaps some sort of NameSpace conflict?