简体   繁体   中英

Ejs2 include(variable) not working

Ejs2 docs say it is possible to do:

exports.get = function(req, res) {

    res.render('layouts/home', {
        page: '../pages/' + 'home'
    });

};

and then within the layouts/home.ejs:

<!-- !PAGE CONTENT! -->
    <div>

        <!-- Sidenav/menu -->
        <% include ../partials/sidebar %>

        <!-- Content -->
        <% include(page) %>

        <!-- Footer -->
        <% include ../partials/footer %>
    </div>

but it writes:

 { [Error: ENOENT: no such file or directory, open 'D:\project\views\layouts\(page).ejs']
      errno: -4058,
      code: 'ENOENT',
      syscall: 'open',
      path: 'D:\\project\\views\\layouts\\(page).ejs' }

I installed ejs2. But somehow it does not work. Before this ejs1 worked fine. But i did not have this include(var) functionality.

This may be a little bit late, but I had the same problem and fixed it by changing:

<% include(var) %>

to

<%- include(var) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM