title: Pre-populating Pug form from Express/Node.js web app
body: <p>I have a Node.js web app built with Express and am trying to populate a Jade template after querying MongoDB. I would like to populate the Jade template with these values.</p>
  
  <p>Something I don't understand is why even when I comment out everything within the collection.find() function, and only have a 'res.render('editresource')' -- the view is not rendered. Am I not understanding something fundamental? </p>
  
  <pre><code>// From pug file (editresource.pug)
  extends layout
  
  block content
      h1 = title
  
      .main.container
          .row
              .col-md-6.col-md-offset-3
                  h1.display-4.m-b-2 Edit Resource
  
                  // register form
                  form(method='POST' action='/edit/editresource')
                      div.form-group
                          label(for='name') Name:
                          input#name.form-control(type='text', name='name', required='', value=locals.dName)
  
  // From  Node.js/Express:
      router.get('/editresource/:id', function(req, res) {
      var db = req.db;
      var resource_collection = db.get('resources');
  
      var resourceId = req.params.id;
  
      resource_collection.find({'_id' : resourceId},{},function(e,docs){
          // res.render('editresource', {
          //  name : 'asdf'
          // });
  
          //res.locals.dName = docs[0].name;
          //res.render('editresource')
  
          res.render('editresource', { 'viewpost' : docs[0].name })
  
          //res.name = docs[0].name;
          //res.render('editresource', { name : docs[0].name });
      });
  // attempting to call res.render('editresource') here does not work??
  });
  
  // All of this is fired by this function when a link is clicked
  function editResource(event) {
      $.ajax({
          type: 'GET',
          url: '/edit/editresource/' + $(this).attr('rel')
      }).done(function( response ) {
  
          if (response.msg === '') {
          }
          else
              alert('Error: ' + response.msg);
      });
  };
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/questions/19386901/pre-populating-html-jade-from-express-node-js-web-app">a similar question</a> but using res.locals does not work, nor does sending the whole object.</p>