dustjs icon indicating copy to clipboard operation
dustjs copied to clipboard

How to render dust template located in different folders?

Open nanachimi opened this issue 10 years ago • 6 comments

Hi,

I have the following set up:

app.engine('dust', engines.dust); app.set('view engine', 'dust'); app.set('views', path.join(__dirname, path.join('public', 'templates')));

Now in /public/templates/ i have many subfolders. For expl sub1, sub2 where my templates are located. How can i from the folder /routes/sub1/ render the templates located in /public/templates/sub1.

I have try this: res.render('sub1/index', {title: 'Sub1'}); res.render('sub1.index', {title: 'Sub1'});

but this don't work

Regards Micky

nanachimi avatar Oct 11 '15 18:10 nanachimi

What is engines? Are you using consolidate? If not, which rendering engine?

What express version?

sethkinast avatar Oct 11 '15 19:10 sethkinast

yes i'm using consolidate and i hav the express version 4.13.3

nanachimi avatar Oct 11 '15 20:10 nanachimi

This looks pretty reasonable. I will be able to test an example tomorrow. Until then:

Consolidate expects your files to end in .dust unless you pass it a different extension.

If you aren't attached to consolidate, we have an example in the repo using Hoffman: https://github.com/linkedin/dustjs/blob/master/examples/streaming-hoffman/app.js

sethkinast avatar Oct 11 '15 20:10 sethkinast

Thanks! It works with hoffman. Now i can render using res.render('sub1/index', {title: 'Sub1'}); But by using partial (> layout) the engine still look the layout.dust template in the /public/template folder instead of /public/template/sub1/

nanachimi avatar Oct 11 '15 21:10 nanachimi

Yes, template paths in dust are absolute, not relative. I believe a couple people have worked on renderers that automatically transform relative paths.

In dust, template names have to be unique, so you can't register two templates under the name "layout", even if they are in separate folders (the file path is just an implementation detail).

On Sun, Oct 11, 2015, 2:54 PM mickyloranger [email protected] wrote:

I change consolidate with hoffman and i can render with res.render('sub1/index', {title: 'Sub1'}); But the engine still look at the layout.dust (i'm using partial) in the /public/template folder instead of /public/template/sub1/

— Reply to this email directly or view it on GitHub https://github.com/linkedin/dustjs/issues/707#issuecomment-147249500.

sethkinast avatar Oct 12 '15 00:10 sethkinast

can you please me give more infos about people who are worked on that?

nanachimi avatar Oct 12 '15 00:10 nanachimi