I am trying to render partials using node.js. Here is my code.
app.js:
var express = require('express')
, routes = require('./routes');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
var products = require('./products.js');
app.get('/products', function(req, res) {
res.render('products/index', {locals: {
products: products.all
}
});
});
app.listen(3000);
When I go to localhost:3000/products it should render index.jade which is in the products folder which is in the views folder.Above I set the views directory using app.set('views', __dirname + '/views');
index.jade:
h1 Products:
#products!= partial('partials/product', {collection: products})
This should render the partial equivalent to (partials/product.jade) because jade is my view engine.
I am getting an error back saying “partial is not defined”
Any help would be great. thanks
UPDATE:
That solved my partial error thank you. I reinstalled 2.5.9.
Check what version of Express JS you have installed — you may have the 3.0 alpha:
If you’re interested in trying the alpha, be sure to checkout the documentation on Migrating from 2.x to 3.x. In it, you’ll notice that
res.partial()andpartial()(within templates) have been removed — as described under “View system changes:”You can see an example of the intent in the linked article, Use Jade blocks, not layouts.
If you’re not interested, then just make sure you have 2.x installed.
Or via
package.json: