Home > Software engineering >  How can I properly use moment inside of pug?
How can I properly use moment inside of pug?

Time:04-08

I'm trying to use moment to format a date in PUG. This is my code:

  table(style='width:50%', border='2')
      tr
        th Event Title
        th Date
        th Coin
        th Name
        th Description
      each event in data.body
        tr
          td(style='text-align: center') #{event.title['en']}
          td(style='text-align: center') #{moment(event.date_event).format('YYYY-MM-DD')}
          td(style='text-align: center') #{event.coins[0].symbol}
          td(style='text-align: center') #{event.coins[0].name}

I've tried looking for examples here but I couldn't make it work with the ones I found. PS: I have the library installed and imported to all my local app files already.

Can anyone help me with that?

Cheers

CodePudding user response:

app.locals.moment = require('moment');

or

script(src='moment.min.js')
  • Related