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

Custom template not displayed in browser #14

Open
akobashikawa opened this issue Nov 18, 2015 · 8 comments
Open

Custom template not displayed in browser #14

akobashikawa opened this issue Nov 18, 2015 · 8 comments

Comments

@akobashikawa
Copy link

I am using express with nunjucks:

var nunjucks = require('nunjucks');
nunjucks.configure('views', {
    autoescape: true,
    noCache: true,
    express: app,
    watch: true
});

In a template, I try:

{{ messages('test/messages.html', locals) | safe }}

I put console.logs in express-messages/index.js to ensure output is ok. However, browser is not showing.

@akobashikawa
Copy link
Author

I think html generated in callback via render in too late and function returns default empty output:

      if (template) {
        locals = locals || {};
        locals.messages = flash;
        res.render(template, locals, function (err, html) {
          if (html) {
            output = html;
          }
        });
      } else {
         //...
      }
      return output; // I THINK THIS LINE WINS TO CALLBACK IN RENDER

@artcommacode
Copy link

Not quite sure what is going on here, paging @agraboso!

@davepwsmith
Copy link

Any movement on this?

@artcommacode
Copy link

Paging @agraboso again!

@agraboso
Copy link
Contributor

I believe @akobashikawa's assessment is correct. The obvious fix would be to render the template synchronously, but express disallows that by not exposing the rendering engine(s). We might have to simply import a templating library...

@artcommacode
Copy link

Thanks @agraboso. Would that not end up to blocking the request though? Is there any way to handle this async? Maybe we could take in next and call that from within the function or change the signature to return our own callback?

@agraboso
Copy link
Contributor

agraboso commented Jun 6, 2016

@artcommacode: I don't see how to do this async at all. After a good deal of thought, I think the best way to deal with this is to delegate rendering to the user in exactly the way flash does — so maybe we should deprecate this module and point users to flash.

@nahwinrajan
Copy link

so we can't use custom template for this package ....

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