Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 19 18:41
    coolaj86 commented #141
  • Sep 19 18:40
    coolaj86 commented #141
  • Sep 19 18:32
    shadowtime2000 closed #141
  • Sep 19 18:32
    shadowtime2000 commented #141
  • Sep 19 18:29
    shadowtime2000 unlabeled #141
  • Sep 19 18:26
    shadowtime2000 labeled #141
  • Sep 19 18:20
    shadowtime2000 closed #139
  • Sep 19 18:20
    shadowtime2000 locked #139
  • Sep 19 18:16
    shadowtime2000 commented #143
  • Sep 18 08:41
    AmirABody opened #143
  • Sep 18 01:58
    mikeerickson closed #142
  • Sep 17 17:06
    mikeerickson opened #142
  • Sep 16 20:39
    coolaj86 commented #141
  • Sep 16 20:33
    coolaj86 edited #141
  • Sep 16 20:31
    coolaj86 edited #141
  • Sep 16 20:30
    coolaj86 edited #141
  • Sep 16 20:27
    coolaj86 edited #141
  • Sep 16 20:27
    coolaj86 opened #141
  • Sep 14 20:12
    coolaj86 commented #140
  • Sep 14 20:09
    coolaj86 opened #140
dtrikannad
@dtrikannad
Do you guys have any samples of using flash messaging with eta?
shadowtime2000
@shadowtime2000
@dtrikannad What do you mean by flash messaging?
dtrikannad
@dtrikannad
thank you @shadowtime2000, I'm using eta with express-flash. It is a mechanism that allows me to save messages throughout the code and present them to the user on the next pages...is there another mechanism that allows me to do this? It would appear that it works just fine if I don't call render
Emmanuel Segun-Lean
@LeanKhan
@dtrikannad hey, i use "express-flash-message" note the name. So after creating a flash message and redirecting, you can add an if condition to check if there are any messages at all, then render them.
@dtrikannad you can even have them in a separate partial. Then you can also use them with a css framework that has alert components. You can also choose to use either cookie-sessions or regualr sessions. Hope this helps?
dtrikannad
@dtrikannad
Thank you @LeanKhan! That library does work with eta, but it doesn't allow me to have simultanous messages across multiple keys. For example, I cannot have an 'Info' and 'Success' message at the same time.
dtrikannad
@dtrikannad
This is why I was looking at the "express-flash" library
Emmanuel Segun-Lean
@LeanKhan
@dtrikannad you can actually, but youll juat have to repeat the statement that creates the flash messages. You can also use "Express-flash" however, it was not working well for me.
Emmanuel Segun-Lean
@LeanKhan

This is how I do it:


In my route... maybe after a login:
await req.flash('error', 'Something bad happened');
await req.flash('info', 'idk mehn, something happened sha');
await req.flash('success', 'Something good happened');

// bonus: I have this block in an app.use
// middleware so it captures all alerts for all routes

res.locals.alerts = {
    info: await req.consumeFlash('info'),
    error: await req.consumeFlash('error'),
    success: await req.consumeFlash('success'),
};

Then in your template:
<% alerts.forEach(function(alert){ %>
    <div>
     <%= alert.message %>
    </div>
<% }) %>

You can come up with something better that fits for usecase tho

Of course you add the necessary checks and validations
dtrikannad
@dtrikannad
@LeanKhan hmmm...that didn't work for me before...gonna try again...thanks for the tip! :)
dtrikannad
@dtrikannad
@LeanKhan I tried again, but the first consumeFlash works, but all subsequent consumeFlash calls return nothing...any ideas what could be causing that?
dtrikannad
@dtrikannad
@LeanKhan can you share which version of express-flash-message you're using? I've stepped in to the 2nd consumeFlash and req.session.flashMessage object is null. It gets nullified after the first consumeFlash call. On the first call, req.session.flashMessage contains all the messages, but once it returns, it seems to clear them all out and sets that object to null. any ideas? I'm using the latest 2.0.0
I'm using express-session for my session....here is my code:
dtrikannad
@dtrikannad
let sessionStore = new session.MemoryStore;
const sessionConfig = {
    secret: '[secret goes here]',
    name: 'appname',
    resave: true,
    saveUninitialized: true,
    store: sessionStore,
    cookie : {
      sameSite: 'strict', // THIS is the config you are looing for.
      maxAge: 60000
    },
    secure: false
  };
  app.use(session(sessionConfig));
dtrikannad
@dtrikannad
I wasn't able to get express-flash-message working, but I was able to get express-flash working just fine...thanks for suggesting that...after some trial and error, i was finally able to get express-flash to work just fine.
Emmanuel Segun-Lean
@LeanKhan
@dtrikannad they will return nothing if you previously didn't create any flash message. Did you do req.flash for the other messgae types? "Info", "success"?
@dtrikannad okay, you got express-flash to work? Nice one 👍
Simon Layfield
@simonlayfield
Hello :wave:
Just picked up Eta for something I'm working on so thought I'd tune in.
Simon Layfield
@simonlayfield
I was wondering if anyone who uses the eta-vscode extension for language support in vscode would be able to tel me which version of vscode they're using. It seems it's incompatible with my version (1.45.1).
dtrikannad
@dtrikannad

Anyone know how to call my own functions from within the template. For example, I have a library I've created a function in my utils.js file called exports.helloworld = (req, res) => { return 'Hello World'; }

how can I call helloworld() from within the template?

dtrikannad
@dtrikannad
nevermind...i did something like
        return res.render('pages/organization', {
          user: req.user,
          title: 'My Organizations',
          organizations: orgDetails,
          events: events,
          errorMessages: await req.flash('error'),
          infoMessages: await req.flash('info'),
          successMessages: await req.flash('success'),
          warningMessages: await req.flash('warning'),
          dtFormat: require('dateformat')
        });
where dtFormat takes in the require statement directly and that worked.
shadowtime2000
@shadowtime2000

I was wondering if anyone who uses the eta-vscode extension for language support in vscode would be able to tel me which version of vscode they're using. It seems it's incompatible with my version (1.45.1).

@simonlayfield :wave: Hey, I created eta-vscode. I am running 1.54.3 and it seems to work fine for me

Simon Layfield
@simonlayfield
@shadowtime2000 Hey! :wave: Oh, right. Ermm. I'll check again!
Simon Layfield
@simonlayfield
@shadowtime2000 I updated to 1.54.3 and it works. Thanks!
Simon Layfield
@simonlayfield
What would be the best way to access an environment var from within an eta template without having to pass it down for every view render? Is there a way to set a var globally for all views?
Simon Layfield
@simonlayfield
Oh, silly. Used res.locals.
shadowtime2000
@shadowtime2000
@/all Hey, I would just like to gather all your opinions on maybe transferring from Gitter to Discord. I find when using Gitter it is much harder to keep track of messages and get notified when they come. I think such a change would make it easier for people coming in to ask questions or give feature ideas and stuff because Gitter is not as organized.
Emmanuel Segun-Lean
@LeanKhan
@shadowtime2000 yeah Gitter is not the best. But I haven't used Discord before so why not. Github has this new Discussions feature for repos have you considered that?
shadowtime2000
@shadowtime2000
@LeanKhan Yeah I know about discussions. They are pretty useful, but they aren't as great for stuff like just really really small problems that people are having with their code that they need help with.
Rubin Bhandari
@rubiin
can we include markojs benchmarks as well
shadowtime2000
@shadowtime2000
@rubiin What do you mean? As in including them in the benchmark? I don't think MarkoJS really fits as a template engine because it is more of an isomorphic UI framework
Simon Layfield
@simonlayfield
Hi all - I was wondering if there is a way to catch and display eta template errors in the browser? Using Express, and not sure how to go about it. Any help would be greatly appreciated.
shadowtime2000
@shadowtime2000
@simonlayfield I think you could just use a try {} catch (e) {} to do that inside of the request handler
Simon Layfield
@simonlayfield
Oh, yeah I'll try that.
Andre Mas
@ajmas_gitlab
Currently looking at moving from ejs to eta, but not sure how to inject variables, such that I don't need to do it explicitly it in every res.render() call
Not seeing anything mentioned in the docs and also trying to deal with i18n-express translation block not being available: Error: {} translate is not defined
Andre Mas
@ajmas_gitlab
okay, turns out it is the same, just by default accessible via 'it'
Avery Fay
@btmorex
Hi, I'm trying to use eta in a webworker and webpack is pulling in the cjs version (even though my config works for other npm packages). Anyone have any ideas? I wrote the following stackoverflow question because I'm not sure where the fault lies: https://stackoverflow.com/questions/67560485/webpack-targeting-webworker-wont-import-browser-version-of-a-dependency
Damian
@damiantoczek
Hi everyone, I want to use layouts but it doesn't work. So I have a layout.eta file that has <%~ it.body %> and a home.eta file that has <% layout('layout') %> and some html beneath. The layout renders but the home html doesn't show.
Simon Layfield
@simonlayfield
Hi all - what would be the best way to handle page titles (the html <title> tag) within layouts? Is there a way to avoid defining these every time a layout file is defined inside a template?
Simon Layfield
@simonlayfield
Ah, got it. Added to the route response.
TheoRelativity
@TheoRelativity
Hi everyone, someone tried to use eta with Hapi and vision? :)
NewtTheWolf
@NewtTheWolf

Hey Hey

I hope I can ask this here

How do layouts work?
How do I render a layout?

This is how I understood it:
I have a layout.ejs in which I put in the body <%~ it.body %>

I have an index.ejs where I put <% layout('layout/index') %> at the top but how do I render this now?

Emmanuel Segun-Lean
@LeanKhan
@NewtTheWolf whenever you render index.ejs it will put all the content inside it.body. So layout.ejs can have your navbar, footer etc. And index.ejs can just have some text or something unique to that page. You get?
NewtTheWolf
@NewtTheWolf

@LeanKhan I tried this before and it works flawlessly!

Thanks a lot for the answer!

dcd-api
@dcd-api
rendering in teh clientside is not working webpack give an error you cant use path (core node modules)