-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of docs on pre-compiling doT template #87
Comments
Hi @jiyinyiyong Although I end up just relying on cache and not doing any precompiling, I think this is roughly how you would do it: var dot = require('doT.js');
var template = '<html><body><h1>Header = {{=it.header}}</h1></body></html>';
var compiledTemplate = dot.compile(template);
// You can now use the compiled template as much as you want, e.g.:
console.log( compiledTemplate({header:'First Header' }) );
// = <html><body><h1>Header = First Header</h1></body></html>
console.log( compiledTemplate({ header:'Second Header' }) ); If you are creating an ExpressJS application, then on startup you could include an object with all your compiled templates and use them when needed (either compile on application start or pre-compile into an exported module just to be required on application startup). For anything client-side, compile the templates on the server and create a .JS file to use on the client-side (with the compiled template functions). |
Hi @jiyinyiyong |
@sebowles51 Thanks. I'll check that later when I begin new projects. @olado Well, it's not detailed.. And the code, the var render = dot.process({
path: program.source,
destination: program.dest,
global: program.global
});
if (program.package) {
console.log("Packaging all files into " + program.package);
var fs = require("fs");
var files = [];
var dest = program.dest || './';
if (dest[dest.length-1] !== '/') dest += '/';
var sources = fs.readdirSync(dest);
for(k = 0; k < sources.length; k++) {
name = sources[k];
if (/\.js$/.test(name)) {
files.push(dest + name);
}
}
var result = require("uglify-js").minify(files);
fs.writeFileSync(program.package, result.code);
} https://github.com/olado/doT/blob/master/bin/dot-packer#L31-L52 |
Seconded. Trying to figure out how to compile from .jst file just using api without auto compilation. |
@jkarttunen my solution at last was to use React. The age for string-based template engines is gone. |
As mentioned doT can be pre-compile, but I can't find any detailed introductions on that.
The text was updated successfully, but these errors were encountered: