let str = "Hello <%= include('file', {person: 'John'}); %>",
fn = ejs.compile(str, {client: true});
fn(data, null, function(path, d){ // include callback
// path -> 'file'
// d -> {person: 'John'}
// Put your code here
// Return the contents of file as a string
}); // returns rendered string
Error: Failed to lookup view "events/edit" in views directory "/home/tcb/Mange/NodeApps/myapp11/views"
at Function.render (/home/tcb/Mange/NodeApps/myapp11/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/home/tcb/Mange/NodeApps/myapp11/node_modules/express/lib/response.js:1008:7)
at /home/tcb/Mange/NodeApps/myapp11/routes/events.js:55:11
at /home/tcb/Mange/NodeApps/myapp11/node_modules/mongoose/lib/model.js:4919:18
at processTicksAndRejections (internal/process/task_queues.js:77:11)
/*EJS with express
In Express v4, a very basic setup using EJS would look like the following.
(This assumes a views directory containing an index.ejs page.) */
let express = require('express');
let app = express();
//to set view engine for using EJS
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.render('index', {foo: 'FOO'});
});
app.listen(4000, () => console.log('Example app listening on port 4000!'));
Tags
<% 'Scriptlet' tag, for control-flow, no output
<%_ ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
<%= Outputs the value into the template (HTML escaped)
<%- Outputs the unescaped value into the template
<%# Comment tag, no execution, no output
<%% Outputs a literal '<%'
%> Plain ending tag
-%> Trim-mode ('newline slurp') tag, trims following newline
_%> ‘Whitespace Slurping’ ending tag, removes all whitespace after it