Created
July 23, 2012 23:42
-
-
Save JangoSteve/3166956 to your computer and use it in GitHub Desktop.
Example ExpressJS view with partials
This file contains hidden or 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
app.get('/', function(req, res) { | |
// [clipped] set user | |
res.render('index', {user: user}); | |
}); |
This file contains hidden or 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
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 |
Did you find any solution for this yet? (I am also porting to Express 3.x and wonder how to replace partials)
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?
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
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.