Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
chovy opened this Issue · 27 comments

5 participants

@chovy

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

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

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

@vybs
Collaborator

is npm install working?

For LinkedIn Dust

$ npm install dustjs-linkedin
For LinkedIn Dust helpers

$ npm install dustjs-helpers

@chovy

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
@vybs
Collaborator

trying your code snippet locally

@chovy

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

@vybs
Collaborator

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

@jairodemorais
Collaborator

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.

@vybs
Collaborator

So much for express3:(

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

@jairodemorais
Collaborator

@vybs

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

@chovy
@vybs
Collaborator

@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

@jairodemorais
Collaborator

@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
@chovy

any idea what the problem is?

@chovy

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

@vybs
Collaborator

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

@vybs
Collaborator

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

@chovy

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.

@gilbertbw

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
@jimmyhchan
Owner

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

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

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

@vybs
Collaborator

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

@chovy

yeah, i put a demo up on github.

@vybs
Collaborator

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

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

Just did it!

@chovy

I don't see the link, but thanks.

@vybs
Collaborator

done!

@vybs vybs closed this
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.