Skip to content


Including files in templates #36

trevex opened this Issue · 2 comments

3 participants


I have a few questions concerning doT used along with node.js and express.js:

i18n is working without problems along with doT, but when I wanted to separate the template in - what other
templating engine would call - "blocks", I ran into problems. As far as I am aware doT doesn't support "blocks",
but in theory it's supposed to be capable of including files.

I am rendering my templates using the usual express.js way:

res.render('test.html', {pageTitle:"Test"});

But how can I add stuff to the default defines? To do stuff similar to the advanced example, without doing this
within a template:


I am aware about the partial support, but I need to get a partial in my context first, without redefining it in every template.

Thanking you in anticipation,
Niklas Voss


Hi Niklas,

Do you mean partials/sub-templates by blocks? doT allows to include external and inline sub-templates.

With inline sub-templates, you define something like {{##def.inline1: template {{}} here #}} and then include it with {{#def.inline1}}.

With external sub-templates, you can either put them into a def variable or any variable in scope, including global and then include them: {{#def.subtemplate}} or {{#myglobalvar.subtemplate}} or using any other variable in scope.

In your example, when calling the render function, if you mixin def into the options parameter I think it would work.

I am not using express in my project but it seems they have made changes to express so now it works differently, before doT.compile function was enough for integration with defs and caching. Now with the changes they made, it will compile every time you call render it seems.

doT needs to be added to for express integration with caching. Maybe you could add it there? :)

Sorry for the delay with reply.


doT needs to be added to for express integration with caching.
Maybe you could add it there? :)

Done: tj/consolidate.js#46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.