Partials in doT.js?
Hi I'm new to node and I'm trying to figure out how to load partials from
files using doT.js (http://olado.github.io/doT/index.html) and
consolidate.js (https://github.com/visionmedia/consolidate.js/). I'm
trying to create methods for each section of a page, header/body/footer
etc and merge them all into one.
This is the code I have so far:
var util = require( 'util' ),
fs = require( 'fs' ),
dot = require( 'dot' );
function System( ) {
this.name = 'System';
}
System.prototype._loadFile = function( path ) {
var content;
content = fs.readFileSync( process.argv[ 1 ].replace( /\/[^\/]*$/,
path ) );
content = dot.compile( content ); //tried .template both return funcs?
return content;
};
System.prototype._getMainContent = function( ) {
return this._loadFile( '/controllers/system/views/header.html' );
};
System.prototype.index = function( req, res, next ) {
var content = this._getMainContent( );
res.render( __dirname + '/../system/views/main', {
name: this.name,
main_content: '?' //content?
});
};
module.exports = System;
How do I compile a template into a string that I can pass through another
template or res.render?
Thanks!
No comments:
Post a Comment