title: template layout for PugJs
body: <p>I used NodeJs with Handlebars and thought about switching to PugJs because some functionality is native - using Handlebars requires some helper functions / partials.</p>
  
  <p>In Handlebars I have to define a layout and pass in the template. In PugJs I created two example routes</p>
  
  <p><strong>First route file:</strong></p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  
  router.get('/', (req, res) =&gt; {
      res.render('index', {
          title: 'Home',
          template: 'main'
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>Second route file:</strong></p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  
  router.get('/', (req, res) =&gt; {
      res.render('index', {
          title: 'Page2',
          template: 'pageTwo'
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>As you can see I always have to render my index file and pass in the desired pug file as a template variable.</p>
  
  <p><strong>index.pug</strong></p>
  
  <pre><code>doctype html
  html
    include ./header.pug
    body
      include ./templates/#{template}.pug
  </code></pre>
  
  <p><strong>header.pug</strong></p>
  
  <pre><code>head
    title #{title} template!
  </code></pre>
  
  <p><strong>main.pug</strong></p>
  
  <pre><code>script(src='./client/main.js')
  h1 main content here
  </code></pre>
  
  <p><strong>pageTwo.pug</strong></p>
  
  <pre><code>p pageTwo
  </code></pre>
  
  <p>When rendering the pug files I get this error</p>
  
  <blockquote>
    <p>ENOENT: no such file or directory, open
    '...\views\templates\#{template}.pug'</p>
  </blockquote>
  
  <p>How can I replace <code>#{template}</code> with the correct template variable?</p>