Including files in templates #36

Closed
trevex opened this Issue Jul 19, 2012 · 4 comments

Comments

Projects
None yet
5 participants
@trevex

trevex commented Jul 19, 2012

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:

{{#def.loadfile(...)}}

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

@olado

This comment has been minimized.

Show comment
Hide comment
@olado

olado Jul 24, 2012

Owner

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 {{=it.foo}} 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 https://github.com/visionmedia/consolidate.js for express integration with caching. Maybe you could add it there? :)

Sorry for the delay with reply.

Owner

olado commented Jul 24, 2012

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 {{=it.foo}} 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 https://github.com/visionmedia/consolidate.js for express integration with caching. Maybe you could add it there? :)

Sorry for the delay with reply.

@Sannis

This comment has been minimized.

Show comment
Hide comment
@Sannis

Sannis Jul 26, 2012

doT needs to be added to https://github.com/visionmedia/consolidate.js for express integration with caching.
Maybe you could add it there? :)

Done: visionmedia/consolidate.js#46

Sannis commented Jul 26, 2012

doT needs to be added to https://github.com/visionmedia/consolidate.js for express integration with caching.
Maybe you could add it there? :)

Done: visionmedia/consolidate.js#46

@Dabnis

This comment has been minimized.

Show comment
Hide comment
@Dabnis

Dabnis Jul 24, 2016

I am also using dot with node express and would like to solve the following:

I store system commands in JSON string notation and would like to place these cmd's within my dot templates. Here is an example cmd in JSON string :
cb : '{"tm" : "users","cmd": "delete_user", "params" : {"_id" : "[[=user._id]]"} } ' : this is passed to th etemplate as 'cb'.
As you can see it is designed to parse the user._id field from the User data which is also passed to the template.
placing data-cb='[[=model.cb]]' within the template results in : '{"tm" : "users","cmd": "delete_user", "params" : {"_id" : "[[=user._id]]"} } '
As you can see the [[=user._id]] part does not get parsed with the user_id field.

Have you any suggestions for a solution to my problem?

Thanks Jonathan

Dabnis commented Jul 24, 2016

I am also using dot with node express and would like to solve the following:

I store system commands in JSON string notation and would like to place these cmd's within my dot templates. Here is an example cmd in JSON string :
cb : '{"tm" : "users","cmd": "delete_user", "params" : {"_id" : "[[=user._id]]"} } ' : this is passed to th etemplate as 'cb'.
As you can see it is designed to parse the user._id field from the User data which is also passed to the template.
placing data-cb='[[=model.cb]]' within the template results in : '{"tm" : "users","cmd": "delete_user", "params" : {"_id" : "[[=user._id]]"} } '
As you can see the [[=user._id]] part does not get parsed with the user_id field.

Have you any suggestions for a solution to my problem?

Thanks Jonathan

@epoberezkin

This comment has been minimized.

Show comment
Hide comment
@epoberezkin

epoberezkin Oct 30, 2016

Collaborator

@Dabnis please submit as a separate issue and clarify. I don't understand your use case.

Collaborator

epoberezkin commented Oct 30, 2016

@Dabnis please submit as a separate issue and clarify. I don't understand your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment