Skip to content

Instantly share code, notes, and snippets.

@JamesEggers1
Created March 26, 2013 13:12
Show Gist options
  • Save JamesEggers1/5245252 to your computer and use it in GitHub Desktop.
Save JamesEggers1/5245252 to your computer and use it in GitHub Desktop.
An example of what I'd like to be able to do in Jade.
!!! 5
head
body
//- Currently this is the norm and works find
include path/to/partial
//- This is what I want to be able to do - provide the base directory from the route/rendering data.
include #{dir_from_route}/to/partial
@adunkman
Copy link

How would you do such at the route/middleware layer?

A-like so:

app.use(function (req, res, next) {
  res.locals.renderSomething = function (filename, locals) {
    // Presumably, you'd use the jade module to render the file to a string here

    // Return the rendered string.
    return results;
  };

  next();
});

Then, in your views:

div.renderedStuff= renderSomething("your filename.jade", locals);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment