title: Using Twig with a Slim application
body: <p>I'm using the Slim framework for a simple website I'm developing and would also like to use the Twig templating engine.</p>
  
  <p>I've installed Slim, Slim Extras and Twig and my <code>index.php</code> file has the following content:</p>
  
  <pre><code>&lt;?php
  
  /* Require and initialize Slim and Twig */
  require 'Slim/Slim.php';
  \Slim\Slim::registerAutoloader();
  require 'Twig/lib/Twig/Autoloader.php';
  Twig_Autoloader::register();
  
  $app = new \Slim\Slim(array(
      'view' =&gt; new \Slim\Extras\Views\Twig()
  ));
  
  /* Application routes */
  $app-&gt;get('/', function () {
      $pageTitle = 'hello world';
      $body = 'sup world';
  
      $app-&gt;view()-&gt;setData(array('title' =&gt; $title, 'body' =&gt; $body));
      $app-&gt;render('index.html');
  });
  
  /* Run the application */
  $app-&gt;run();
  </code></pre>
  
  <p>However, this results in an error: <code>Fatal error: Call to a member function view() on a non-object in C:\xampp\htdocs\index.php on line 18</code></p>
  
  <p>I'll admit I have no idea how to properly use Twig with Slim. I followed a StackOverflow post on the directory structure and how to load Twig, but I don't know how to add some custom data to a view and I don't know where the view files for Twig should be stored.</p>
  
  <p>I googled but a lot of the information is for older versions of Slim and the Slim documentation itself is lacking.</p>
  
  <p>Thanks!</p>