-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Includes now throwing errors #477
Comments
Huh? Link seems to be broken. |
It's in the current changelog: "Removed legacy preprocessor include." That usage of include is leftover from the very old v1, and was left for one major version (and for quite a long time) for backward compatibility. We are following the semver convention of a major version bump when changing the public API. In fact, this hacky legacy feature was never actually documented in v2, but there were tests for it, so we have done a major version bump to v3. If your app depends on this feature, you can continue to install a v2.x. Otherwise, you can convert to the modern |
Ok, sorry for the lacking research. For anyone else with the issue, you can change the old version of include: |
I've been using the |
the major difference is that include 'file.ejs' has passed all parameters as a side effect, but include('file.ejs') does not. Any idea how I can pass the whole data context to the include method to get an easy transition? |
Well, what I meant is that my gulp task gives me an output that has the .pipe(through2.obj(function(file, enc, next) {
try {
var contents = file.contents.toString();
var compiledFunction = ejs.compile(contents, {
filename: file.path,
client: true
}).toString();
file.contents = new Buffer(compiledFunction);
file.path = replaceExt(file.path, '.js');
} catch(err) {
this.emit('error', new PluginError('gulp-ejs-precompiler', err));
}
next(null, file);
})) It works with v2.x and the preprocessor directive, but not with v3.x and the function call. |
@simllll By default, the local variables live in an object called > let ejs = require('ejs');
undefined
> ejs.render('<%- JSON.stringify(locals); %>', {foo: 'FOO', bar: 'BAR'});
'{"foo":"FOO","bar":"BAR"}'
`` |
Thanks, this helps already a lot to merge the object with temporary data. But is there also something that referes to the current scope variables? E.g. |
@mde: is there any way with ejs 3+ to precompile Is there no way to separate the compiled templates from the raw EJS files when using As a note, I only use |
You can provide a custom This is the default behaviour: Lines 647 to 656 in d8ae91d
|
Breaking change. Solution obtained from [1]. [1]: mde/ejs#477
* [EJS] Install ejs-lint to help investigate error messages [1]: https://www.npmjs.com/package/ejs-lint * [DB] Use in-memory DB during dev environment * [EJS] Update include to match v3 Breaking change. Solution obtained from [1]. [1]: mde/ejs#477 * [EJS] Define the LOGGED_IN template var in 404 and 500 pages Otherwise we get a fatal error. Breaking change. * [DB] Always define exports.MONGO_URI in config.js to avoid compiler errors
After updating to the latest version of EJS, I am now getting errors while compiling my EJS templates.
The error message is:
SyntaxError: Unexpected token .
I believe the lines causing these issues are
include
lines such as the following, as when removing such lines the errors cease.<% include ../partials/bootstrap/bootstrap_header.ejs %>
<% include ../partials/main_components/head_to_body.ejs %>
I couldn't find any changes in the changelog which would cause this. Thanks,
The text was updated successfully, but these errors were encountered: