1

I have decided to use Macaw Router Class for my simple projects, so just want to know How I can integrate Twig Template System with Macaw. Is there a way to do this?? Twig is running, macaw is running fine, But wen I try to do some thing like this, it shows ' Call to a member function render() on a non-object', here is code i use

require 'Macaw.php';
use \NoahBuscher\Macaw\Macaw;

require_once 'lib/Twig/Autoloader.php';
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem('views');
$twig = new Twig_Environment($loader, array(
    'cache' => 'cache',
));
   Macaw::get('/', function() {
       $twig->render('home.twig', array('text' => 'Hallo World'));
});

see I am not a hardcore developer, so may be it is a utter foolish question, but again it will be so helpful if somebody show me how can use both systems.

Salih K
  • 701
  • 2
  • 12
  • 31

1 Answers1

3

You need to import the $twig variable into the function's scope using use:

Macaw::get('/', function() use ($twig) {
    // ...
});
helmbert
  • 35,797
  • 13
  • 82
  • 95