Noty.js notifications not displaying in EJS template

67 Views Asked by At

I am trying to use Noty.js to display notifications in my Express.js application using EJS templates. However, the notifications are not displaying as expected.

In my layout.ejs file, I have included the Noty CSS and JS files:

<head>
    <title><%= title %></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.css"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/noty/3.1.4/noty.min.js"></script>
    <!-- ... Other CSS and JS files ... -->
</head>

I am trying to display a success notification if the flash.success message exists in the EJS template. Here's the relevant part of my layout.ejs:

<%- script %>
        
<script>
    <% if (flash.success && flash.success.length > 0) { %>
        new Noty({
            theme: 'relax',
            text: '<%= flash.success %>',
            type: 'success',
            layout: 'topRight',
            timeout: 1500
        }).show();
    <% } %>
</script>

I have confirmed that the flash.success message is being set correctly in my route before rendering the EJS template. Also, the flash variable is properly passed to the EJS template through a custom middleware.

Despite these steps, the Noty notification is not showing up. I have checked the browser console for any errors, but there are no JavaScript errors.

Is there anything I might be missing or doing incorrectly? I would appreciate any help in resolving this issue. Thank you!

0

There are 0 best solutions below