Giter VIP home page Giter VIP logo

Comments (3)

artcommacode avatar artcommacode commented on June 3, 2024 1

Sorry for the late reply @dearwish, I obviously hadn't set up my GitHub notifications correctly!

Anyway, I think this is a little out of the remit of express-messages. Personally, when I need some custom templating I bypass it altogether and set up a bit of custom middleware like so:

app.use(function (req, res, next) {
  var flash = req.flash()
  res.locals.messages = Object.keys(flash).reduce(function (messages, type) {
    flash[type].forEach(function (message) {
      messages.push({type: type, message: message})
    })
    return messages
  }, [])
  next()
})

Now I can access messages in my jade templates:

ul.messages
  each message in messages
    li(class="#{message.type}")= message.message

Or for EJS:

<ul class="messages">
  <% messages.forEach(function (message) { %>
    <li class="<%= message.type %>"><%= message.type %></li>
  <% }) %>
</ul>

I hope this helps. Of course, if you and others do believe that custom templating should be added to express-messages then that's something I'll look into.

from express-messages.

artcommacode avatar artcommacode commented on June 3, 2024 1

Landed in 1225b2d, with thanks to @agraboso.

from express-messages.

dearwish avatar dearwish commented on June 3, 2024

Thank you for addressing my question @artcommacode, but I really liked the concept of express-messages, because the template outcome is very short and clean <%- messages() %>.

In my case I just customized your module for my local utility to fit the message markup to Zurb Foundation alert boxes.

Of course, this is not the ultimate way to handle such tasks, but my project timeline was very tight, thus I didn't have a time for healthy contribution for this functionality. Looking forward, I think it will be a good thing to provide the markup templating functionality, because it differs for each framework.

I will also think about this and will try to implement something more generic when I will have some more time.

Thanks again.

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.