• DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        EJS not able to render page due to class declaration

        315 Views Asked by Fiore At 23 April 2021 at 10:18 2025-12-16T23:10:00.597000
        <header class="main-header">
        <nav class="main-header__nav">
            <ul class="main-header__item-list">
                <li class="main-header__item"><a class="<%= path === '/' ? 'active' : '' %>" href="/">Shop</a></li>
                <li class="main-header__item"><a class="<%= path === '/admin/add-product' ? 'active' : '' %>" href="/admin/add-product">Add Product</a></li>
            </ul>
        </nav>
        

        When I try to render the page in my node js application I am getting an error. Saying there is an error

        I am not so used to writing ejs but when I remove the class="<%= path === '/' ? 'active' : '' %>" in the navigation.ejs it seems to work

        enter image description here

        Error Image

        node.js ejs templating-engine
        Original Q&A
        1

        There are 1 best solutions below

        2
        Nandeep Barochiya Nandeep Barochiya On 23 April 2021 at 10:35

        Use <%- include('RELATIVE/PATH/TO/FILE'); %> to embed an EJS partial in another file.

        • The hyphen <%- instead of just <% tells EJS to render raw HTML.
        • The path to the partial is relative to the current file.
        • and also use ; at end of include

        Here is an example...

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <%- include('../partials/head'); %>
        </head>
        <body class="container">
        
        <header>
            <%- include('../partials/header'); %>
        </header>
        
        <main>
            <div class="jumbotron">
                <h1>This is great</h1>
                <p>Welcome to templating using EJS</p>
            </div>
        </main>
        
        <footer>
            <%- include('../partials/footer'); %>
        </footer>
        
        </body>
        </html>
        

        Related Questions in NODE.JS

        • How to solve CERT_UNTRUSTED error in nodemailer
        • Run a loop over a callback, node js
        • Implementing prerender.io middleware in sails.js
        • Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
        • formatting path string in javascript
        • One to One screensharing using WEBRTC
        • Create polygon from grid (for collisions)
        • Strange npm behavior when installing packages like grunt
        • Convert JSON.gz to JSON in node js
        • "Your npm version is outdated." but it's not. While install yo
        • Why put methods on the prototype of a class instead of declaring them in the constructor?
        • Node JS Async Response
        • mongoose get property from nested schema after `group`
        • Cannot Receive Incoming call on Twilio android Client
        • How can I change a specific line in a file with node js?

        Related Questions in EJS

        • Node Express Routing Problems
        • html-pdf with ejs template
        • Create variables and require packages in EJS
        • Adding attributes for fields using ejs view helpers
        • Ejs input_field_tag method setting type attribute as 5
        • How to get post params in app.post
        • in metaworks, boolean property value is not available in the EJS
        • Passing a var from server to client
        • Add modal window in ejs file
        • Using Express to render an .ejs template for AngularJS and use the data inside AngularJS $scope
        • template to transform html code
        • cache and avoid reloading html,css, and js files
        • SyntaxError: Unexpected identifier in manacc.ejs while compiling ejs
        • Date value not showing value pulled from database
        • Url path in ExpressJS + NodeJS

        Related Questions in TEMPLATING-ENGINE

        • How can I use a GET url to identify if the user is accessing the backend?
        • How to create a custom Twig function class, without using a static method?
        • If statements in template system
        • Proper way of printing variable only if exists, in .tpl smarty file
        • how to check true condition in iCanHaz (Moustache Template engine)
        • Business user templating language for Java
        • Using Webpack 5 - How to reference files with a [contenthash] substitution in html when using a server-side templating engine?
        • php mvc + templating engine
        • Where to render Ajax search results in an object oriented approach using Coldfusion?
        • How to write single-line comments in an H2O template
        • Handlebars registerPartial() is not working
        • Are there any more Unobtrusive Server-side Scripts like hQuery for easier templating?
        • Javascript templating library that infers used variables and dependencies
        • Making a simple templating engine in PHP
        • Problem with html templating using express

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates