Giter VIP home page Giter VIP logo

Comments (10)

di-ego02 avatar di-ego02 commented on June 4, 2024 8

when you utilize this codeapp.use(require('connect-flash')()); app.use(function (req, res, next) { res.locals.messages = require('express-messages')(req, res); next(); }); taken from the documentation here it specifies that you need to invoke res.local.messages in your template, i e <%-messages()%> but in handlebars you can't write js in the curly braces. So we must call res.local.messages before hand, i e res.locals.messages = require('express-messages')(req, res)(); which will return the flash message object! in your handlebar template you access the key 'messages' like this {{{messages}}}

from express-messages.

artcommacode avatar artcommacode commented on June 4, 2024 1

Good to hear, I'll try and add it to the docs once I get the chance.

from express-messages.

Gauravkandpal001 avatar Gauravkandpal001 commented on June 4, 2024 1

@dalalRohit My error was I forgot to add ( ) at the end of below line of code. :
res.locals.messages = require('express-messages')(req, res)();
in handlebars use : {{{message}}}
to display your message

{{{messages}}} {{#if errors}} {{#each errors}}
{{msg}}
{{/each}} {{/if}} {{{body}}}
{{>login}}

from express-messages.

ERPedersen avatar ERPedersen commented on June 4, 2024

bump

from express-messages.

artcommacode avatar artcommacode commented on June 4, 2024

Thanks @di-ego02, can you confirm this work for you @andeersg, @ERPedersen?

from express-messages.

andeersg avatar andeersg commented on June 4, 2024

Yes, I have done something similar (or exactly the same I see):

app.use(flash());
app.use(function (req, res, next) {
  res.locals.messages = require('express-messages')(req, res);
  next();
});

So I guess we can close this :)

from express-messages.

artcommacode avatar artcommacode commented on June 4, 2024

Thanks for the confirmation.

from express-messages.

ERPedersen avatar ERPedersen commented on June 4, 2024

Works for me too :) I did somewhat the same 👍

from express-messages.

Gauravkandpal001 avatar Gauravkandpal001 commented on June 4, 2024

Thanks de-ego02 you solved my issue of using handlebars with express.

from express-messages.

dalalRohit avatar dalalRohit commented on June 4, 2024

@Gauravkandpal001 Can you show me how did you write the handlebars template code for this? I'm stuck on that only.

from express-messages.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.