0

I am including a header.def file in index.dot using {{#def.header}} snippet and rendering the index.dot file using the following snippet.

var dotjs = require('dot');
var dots = dotjs.process({ path: "./views"});
app.get('/',function(request, response){
    response.send(dots.index());
});

What I also wish to do is render only the header on separate url. Something like:

app.get('/header',function(request, response){
    response.send(dots.header()); // header.def is not compiled to a dot.header function
});
Saurabh Kumar
  • 125
  • 11

1 Answers1

0

Maybe you can create another .def file (for instance "onlyHead.dot") and include the static header in that one without anything else. Then send onlyHead.dot in the same way as you do.

You could also use the template engine doing something like 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 your views you can render it like this (with router.get or as you have it with app.get):

app.get('/',function(request, response){
    var myData = {
       title : 'My title',
       someData : 'My Data'}
    response.render('index', myData);
});

Your index.dot template can then look something like this:

{{#def.static}}
<h1>{{=it.title}}</h1>
<div>The requested data is: {{=it.someData}} </div>

See my answer here

Community
  • 1
  • 1