Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

how to use template with express 3.x? #150

Closed
chovy opened this Issue Sep 19, 2012 · 27 comments

Comments

Projects
None yet
5 participants

chovy commented Sep 19, 2012

var dust = require('dustjs-linkedin');

app.set('view engine', 'dust');

I get an error:500 Error: Cannot find module 'dust'

Contributor

vybs commented Sep 19, 2012

is npm install working?

For LinkedIn Dust

$ npm install dustjs-linkedin
For LinkedIn Dust helpers

$ npm install dustjs-helpers

chovy commented Sep 19, 2012

yeah. i installed both of those -- I just need an example of what to put in app.js to get it working.

I tried this, but it is not working:

http://stackoverflow.com/questions/12489739/using-dustjs-linkedin-templates-in-node-js-and-express3-x

chovy commented Sep 19, 2012

That doesn't work...

var dust = require('dust')

Error: Cannot find module 'dust'

On Wed, Sep 19, 2012 at 12:24 AM, Veena Basavaraj
notifications@github.comwrote:

var dust = require('dust');


Reply to this email directly or view it on GitHubhttps://github.com/linkedin/dustjs/issues/150#issuecomment-8681745.

Anthony Ettinger
http://anthony.ettinger.name
anthony@ettinger.name
+1 (831) 406-1123

Contributor

vybs commented Sep 19, 2012

trying your code snippet locally

chovy commented Sep 19, 2012

thanks. i did not run 'npm install dust' -- i figured that is obsolete now.

Contributor

vybs commented Sep 19, 2012

same issue

i am pretty sure the npm publish is the issue. @jairodemorais can you look into this, it is really bad we have it in this state

Contributor

jairodemorais commented Sep 19, 2012

hi @chovy, I will explain u how you should use express 3.x with dustjs-linkedin.

  1. express has 2 config to set. 'view engine' and app.engine

"view engine" just sets the default and that app.engine just maps what engine to use for a given file extension.

so you should do something like this:

   app.set('view engine', 'dustjs-linkedin');
   app.set('views', __dirname + '/views');
   app.engine('dust', dust.compileFromPath);

There is only one problem with this is that the method compileFromPath doesn't exist in dust :p.

You should add a method in the dust object with this signature that Express expects: (path, options, callback)

you can read more about this here: http://expressjs.com/api.html#app.engine.

Another option would be to use consolidate (http://spalatnik.com/blog/?p=54) but unfortunately Consolidate doesn't support the dustjs-linkedin version it only support the old dust version.

Contributor

vybs commented Sep 19, 2012

So much for express3:(

thanks @jairodemorais , would you know how to get our fork into consolidate?

Contributor

jairodemorais commented Sep 19, 2012

@vybs

we should send a pull request in his repo supporting our fork. :) https://github.com/visionmedia/consolidate.js

chovy commented Sep 19, 2012

It looks to me like he supports dustjs-linkedin:

https://github.com/visionmedia/consolidate.js/blob/master/lib/consolidate.js

look at around 135.

On Wed, Sep 19, 2012 at 10:00 AM, Jairo de Morais
notifications@github.comwrote:

@vybs https://github.com/vybs

we should send a pull request in his repo supporting our fork. :)
https://github.com/visionmedia/consolidate.js


Reply to this email directly or view it on GitHubhttps://github.com/linkedin/dustjs/issues/150#issuecomment-8698091.

Anthony Ettinger
http://anthony.ettinger.name
anthony@ettinger.name
+1 (831) 406-1123

Contributor

vybs commented Sep 19, 2012

@chovy can you try the consolidate approach then? if it works, we will update the stackoverflow thread,
if not we will do a PR to support our fork
thanks in advance

Contributor

jairodemorais commented Sep 19, 2012

@chovy @vybs

We should send a message to the consolidate owner because he is using our fork if the original one fails.

take a look:

 try {
      engine = requires.dust = require('dust');
    } catch (err) {
      engine = requires.dust = require('dustjs-linkedin');
    }

chovy commented Sep 19, 2012

500 Error: ENOENT, open 'base.dust'Still doesn't work when I goto /test1
in my browser.

#./views/test1.dust:
test
{>"base.dust"/}
{<main}
Child Content
{/main}

#./views/base.dust
header
{+main}
Base Content
{/main}
footer

#app.js
, dust = require('dustjs-linkedin')
, cons = require('consolidate')
, test = require('./routes/test')

app.engine('dust', cons.dust);
app.set('view engine', 'dust');

app.get('/test1', test.test1);

#./routes/test.js
exports.test1 = function(req, res){
var d = { title: 'Test1' };
res.locals.session = req.session;
res.render('test1', { d: d } );
};

On Wed, Sep 19, 2012 at 10:32 AM, Veena Basavaraj
notifications@github.comwrote:

@chovy https://github.com/chovy can you try the consolidate approach
then? if it works, we will update the stackoverflow thread,
if not we will do a PR to support our fork
thanks in advance


Reply to this email directly or view it on GitHubhttps://github.com/linkedin/dustjs/issues/150#issuecomment-8699271.

Anthony Ettinger
http://anthony.ettinger.name
anthony@ettinger.name
+1 (831) 406-1123

chovy commented Sep 20, 2012

any idea what the problem is?

chovy commented Sep 20, 2012

I uploaded an example. If I use a regular dust template it works, but as soon as I try a partial it fails:

https://github.com/chovy/express-template-demo

Contributor

vybs commented Sep 20, 2012

silly q, how are these partials loaded? dont see a load source

Contributor

vybs commented Sep 20, 2012

nm, it was indeed silly, the render loads and compiles if not there in dust cache

chovy commented Sep 20, 2012

The index.dust template is supposed to override the content block in base.dust...but I get an error.

https://github.com/chovy/express-template-demo/tree/master/demo/views

500 Error: ENOENT, open 'base'

unless I'm mistaken, this is how you're supposed to use a main layout with dust.

I saw your comment on my stackoverflow question: http://stackoverflow.com/questions/12207272/500-error-enoent-open-c-users-gilbert-documents-github-maths4me-base-dust-w/

With consolidate.js partials aren't loaded relative to the views folder, there loaded relative to app root.

Have you accounted for this in your template?

chovy commented Sep 23, 2012

I tried and it still doesn't work:

500 SyntaxError: Expected buffer, comment, partial, reference, section or
special but "{" found. At line : 1, column : 1
{>"/views/base.dust"}
{<content} This is loaded from a partial.
{/content}

On Sun, Sep 23, 2012 at 4:08 AM, Gilbert Bishop-White <
notifications@github.com> wrote:

I saw your comment on my stackoverflow question:
http://stackoverflow.com/questions/12207272/500-error-enoent-open-c-users-gilbert-documents-github-maths4me-base-dust-w/

With consolidate.js partials aren't loaded relative to the views folder,
there loaded relative to app root.

Have you accounted for this in your template?


Reply to this email directly or view it on GitHubhttps://github.com/linkedin/dustjs/issues/150#issuecomment-8797384.

Anthony Ettinger
http://anthony.ettinger.name
anthony@ettinger.name
+1 (831) 406-1123

Contributor

jimmyhchan commented Sep 23, 2012

You have a syntax error. Partials are self closing tags.

{>"/views/base.dust"/}

chovy commented Sep 23, 2012

Thanks. also the "/" needs to be removed. {>"views/base.dust"/}

Contributor

vybs commented Sep 23, 2012

Nice, @chovy looks like you were able to get it working.!

chovy commented Sep 23, 2012

yeah, i put a demo up on github.

Contributor

vybs commented Sep 23, 2012

Lovely. It would be good to link this off the main wiki page.

http://linkedin.github.com/dustjs/

Just did it!

chovy commented Sep 24, 2012

I don't see the link, but thanks.

Contributor

vybs commented Sep 24, 2012

done!

@vybs vybs closed this Sep 24, 2012

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