Closed e-dot closed 3 years ago
This is the intended behaviour because strict: true
makes it so that the EJS code is no longer wrapped inside a with
statement, since it’s disallowed in strict mode.
You can use the destructuredLocals
option to define a snapshot binding of the title
property:
app.set('view options', {
strict: true,
destructuredLocals: ["title"],
})
Thank you - it works perfectly with option destructuredLocals
.
However, after carefully reading the documentation, I'd rather use the locals
object to read values, i.e. updating my template like this:
<!DOCTYPE html>
<html>
<head>
<title><%= locals.title -%></title>
</head>
<body>
<h1><%= locals.title -%></h1>
</body>
</html>
Regards,
E.
I'm trying to enable strict mode in a very simple template but get the error "variable is not defined" (whereas the variable is defined).
The source code (hello.js) and template (home.ejs) is attached to this post and is very simple:
The template is also basic:
When strict mode is true, it fails with this error:
This occurs on Windows, with iisnode and express 4.17.1 (and ejs version 3.1.6).
Please advise - how can I properly enable strict mode in templates?
Regards,
E. strict_mode_error_not_defined.zip