Created
March 26, 2013 13:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 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 |
Trying to figure out how I would push this logic to the server so it's not in the view.
Also express-partials doesn't re-add partial(...) to Jade views, only to EJS. There's a bug because of how the latest version of Jade uses asych rendering now.
One possibility would be to render the partial yoursel by calling into jade and rendering the resulting string in your view. Alternatively, you may be able to create your own partial
method. It would be essentially the same thing, only called from your view.
If the included content is simple enough, skip the rendering altogether and just add a helper method to return a string of it.
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
Have you considered leaving this sort of logic out of your view and just pre-rendering that section using your controller? That might be a good option, if you don't want to use express-partials like @dustyburwell suggested.
Though, if you're thinking "oh man, why can't I just do
!= partial(dir_from_route + "/to/partial")
then use express-partials fo sho.