Skip to content

Instantly share code, notes, and snippets.

@JangoSteve
Created July 23, 2012 23:42
Show Gist options
  • Select an option

  • Save JangoSteve/3166956 to your computer and use it in GitHub Desktop.

Select an option

Save JangoSteve/3166956 to your computer and use it in GitHub Desktop.
Example ExpressJS view with partials
app.get('/', function(req, res) {
// [clipped] set user
res.render('index', {user: user});
});
h1 User widgets
each widget in user.widgets
// Express 2.x
partial('../../widgets/' + widget.name + '/view.jade', {user: user});
// Express 3.x (??)
// Each widget has its own view.jade template, and may be loaded into the app via
// a node module or a git submodule. The widget's view.jade is included by the app
// and has no concept of, or access to, the app's template or view structure.
// Can do this, but haven't been able to get it working where "some_widget" isn't hardcoded
include ../../widgets/some_widget/view.jade
@JangoSteve
Copy link
Copy Markdown
Author

Started using jade include. Haven't figured out a way to codify the filename of the jade file to include, but it can at least be hardcoded.

@regular
Copy link
Copy Markdown

regular commented Oct 9, 2012

Did you find any solution for this yet? (I am also porting to Express 3.x and wonder how to replace partials)

@ironstrider
Copy link
Copy Markdown

I too am looking for a way around this. I cannot believe they thought it was a good idea to completely remove any form of dynamic partial/include. Anything with widgets (in my case, I'm building a HTML form dynamically) is now entirely impossible in Jade. What on earth were they thinking?

@k00k
Copy link
Copy Markdown

k00k commented Mar 3, 2014

For anyone looking for info on includes and partials in Express 3, you can simply do: 'include mypartial.jade' - all variables carry through to your partial from its parent .jade file.

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