javascript - Render def file independently in dot.js -
i including header.def file in index.dot using {{#def.header}} snippet , rendering index.dot file using following snippet.
var dotjs = require('dot'); var dots = dotjs.process({ path: "./views"}); app.get('/',function(request, response){ response.send(dots.index()); });
what wish render header on separate url. like:
app.get('/header',function(request, response){ response.send(dots.header()); // header.def not compiled dot.header function });
maybe can create .def file (for instance "onlyhead.dot") , include static header in 1 without else. send onlyhead.dot in same way do.
you use template engine doing this:
in main app:
/* template = dot*/ var dot = require("dot").process({ path: (__dirname + "/views") }); // view engine setup using .dot files app.engine('dot', function(template, options, cb){ return cb(null, dot[path.parse(template).name](options)); });
then in views can render (with router.get or have app.get):
app.get('/',function(request, response){ var mydata = { title : 'my title', somedata : 'my data'} response.render('index', mydata); });
your index.dot template can this:
{{#def.static}} <h1>{{=it.title}}</h1> <div>the requested data is: {{=it.somedata}} </div>
Comments
Post a Comment