Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ralyodio opened this issue Sep 19, 2012 · 27 comments
Closed

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

ralyodio opened this issue Sep 19, 2012 · 27 comments

Comments

@ralyodio
Copy link

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

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

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

@vybs
Copy link
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

@ralyodio
Copy link
Author

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

@ralyodio
Copy link
Author

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//issues/150#issuecomment-8681745.

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

@vybs
Copy link
Contributor

vybs commented Sep 19, 2012

trying your code snippet locally

@ralyodio
Copy link
Author

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

@vybs
Copy link
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

@jairodemorais
Copy link
Contributor

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
Copy link
Contributor

vybs commented Sep 19, 2012

So much for express3:(

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

@jairodemorais
Copy link
Contributor

@vybs

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

@ralyodio
Copy link
Author

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//issues/150#issuecomment-8698091.

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

@vybs
Copy link
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

@jairodemorais
Copy link
Contributor

@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');
    }

@ralyodio
Copy link
Author

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//issues/150#issuecomment-8699271.

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

@ralyodio
Copy link
Author

any idea what the problem is?

@ralyodio
Copy link
Author

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
Copy link
Contributor

vybs commented Sep 20, 2012

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

@vybs
Copy link
Contributor

vybs commented Sep 20, 2012

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

@ralyodio
Copy link
Author

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
Copy link

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?

@ralyodio
Copy link
Author

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//issues/150#issuecomment-8797384.

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

@jimmyhchan
Copy link
Contributor

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

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

@ralyodio
Copy link
Author

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

@vybs
Copy link
Contributor

vybs commented Sep 23, 2012

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

@ralyodio
Copy link
Author

yeah, i put a demo up on github.

@vybs
Copy link
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!

@ralyodio
Copy link
Author

I don't see the link, but thanks.

@vybs
Copy link
Contributor

vybs commented Sep 24, 2012

done!

@vybs vybs closed this as completed Sep 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants