title: Pagination with Twig
body: <p>I've been trying Twig, and it works well for my small site.</p>
  
  <p>This was the tutorial used:</p>
  
  <p><a href="http://devzone.zend.com/article/13633" rel="noreferrer">http://devzone.zend.com/article/13633</a></p>
  
  <p>However, I've had a look online and cannot find anything to do pagination.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    &lt;html&gt;
    &lt;head&gt;
      &lt;style type="text/css"&gt;
        table {
          border-collapse: collapse;
        }        
        tr.heading {      
          font-weight: bolder;
        }        
        td {
          border: 0.5px solid black;
          padding: 0 0.5em;
        }    
      &lt;/style&gt;  
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h2&gt;Automobiles&lt;/h2&gt;
      &lt;table&gt;
        &lt;tr class="heading"&gt;
          &lt;td&gt;Vehicle&lt;/td&gt;
          &lt;td&gt;Model&lt;/td&gt;
          &lt;td&gt;Price&lt;/td&gt;
        &lt;/tr&gt; 
        {% for d in data %}
        &lt;tr&gt;
          &lt;td&gt;{{ d.manufacturer|escape }}&lt;/td&gt;
          &lt;td&gt;{{ d.model|escape }}&lt;/td&gt;
          &lt;td&gt;{{ d.price|raw }}&lt;/td&gt;
        &lt;/tr&gt; 
        {% endfor %}
      &lt;/table&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the PHP coding for it:</p>
  
  <pre><code>&lt;?php
  // include and register Twig auto-loader
  include 'Twig/Autoloader.php';
  Twig_Autoloader::register();
  
  // attempt a connection
  try {
    $dbh = new PDO('mysql:dbname=world;host=localhost', 'root', 'mypass');
  } catch (PDOException $e) {
    echo "Error: Could not connect. " . $e-&gt;getMessage();
  }
  
  // set error mode
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  // attempt some queries
  try {
    // execute SELECT query
    // store each row as an object
    $sql = "SELECT manufacturer, model, price FROM automobiles";
    $sth = $dbh-&gt;query($sql);
    while ($row = $sth-&gt;fetchObject()) {
      $data[] = $row;
    }
  
    // close connection, clean up
    unset($dbh); 
  
    // define template directory location
    $loader = new Twig_Loader_Filesystem('templates');
  
    // initialize Twig environment
    $twig = new Twig_Environment($loader);
  
    // load template
    $template = $twig-&gt;loadTemplate('automobiles.tpl');
  
    // set template variables
    // render template
    echo $template-&gt;render(array (
      'data' =&gt; $data
    ));
  
  } catch (Exception $e) {
    die ('ERROR: ' . $e-&gt;getMessage());
  }
  ?&gt;
  </code></pre>
  
  <p>What would I need to do to get the results paginated within Twig?
  Otherwise my site works perfectly well!</p>
  
  <p>thanks, JC</p>