How to use the ejs/ejs.render function in ejs

To help you get started, we’ve selected a few ejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github persvr / pintura / jsgi / templated.js View on Github external
exports.renderPartial = function(template, object){
	var include = function(template, fallback){
		if (!template) template = '';
		while (true) try {
			return require('promised-io/fs').read(exports.templatesDir + '/' + template, 'utf8');
		} catch (x) {
			if (!fallback || template === fallback)
				return null;
			template = fallback;
		}
	};
	//template: request.nodeRequest.url.replace /\?.*$/, ''
	var engine = require('ejs/ejs');
	var str = include(template, template.substring(template.lastIndexOf('.')));
	var html = engine.render(str, {
		context: engine, // N.B. this will be 'this' in templates
		locals: object, // variables available to the templates
		cache: false, // TODO: optify
		filename: template
	});
	return [html];
};