简体   繁体   English

Node.js:SyntaxError:意外令牌:编译ejs时

[英]Node.js: SyntaxError: Unexpected token : while compiling ejs

I am trying to apply filter to EJS using Node.JS and I am getting the below error. 我正在尝试使用Node.JS将过滤器应用于EJS,但出现以下错误。 I want the message content to be displayed in uppercase. 我希望邮件内容以大写形式显示。

D:\Apps\Templating\ejs>node server.js
D:\Apps\node_modules\ejs\lib\ejs.js:470
      throw e;
            ^
SyntaxError: Unexpected token : while compiling ejs
    at Function (native)
    at Object.Template.compile (D:\Apps\node_m
odules\ejs\lib\ejs.js:460:12)
    at Object.compile (D:\Apps\node_modules\ej
s\lib\ejs.js:288:16)
    at handleCache (D:\Apps\node_modules\ejs\l
ib\ejs.js:147:16)
    at Object.exports.render (D:\Apps\node_mod
ules\ejs\lib\ejs.js:315:10)
    at Object.<anonymous> (D:\Apps\Templating\
ejs\server.js:3:17)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

This is my code- server.js: 这是我的代码server.js:

var ejs = require('ejs');
var template = "<%=: message | upcase %>";
console.log(ejs.render(template,{message : 'hello ejs with filter'}));

I have installed ejs using the package manager and it is working for normal scripts with out filters(:). 我已经使用软件包管理器安装了ejs,它适用于没有filter(:)的普通脚本。 EJS version downloaded is the latest- 2.3.3 and node version is 0.12.4. 下载的EJS版本是最新的2.3.3,节点版本是0.12.4。

npm install ejs

Any help will be appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

当前版本的ejs (v2.3.3)不支持过滤器,该过滤器已从版本2中删除。如果要使用过滤器,则需要安装1.x版本:

$ npm i ejs@1.x

I found out this now. 我现在发现了。 EJS made some changes from version 2 onwards including removal of filter feature. EJS从版本2开始进行了一些更改,包括删除过滤器功能。 https://github.com/tj/ejs https://github.com/tj/ejs

在ejs v2中,必须放置不带=或-如果存在正常的代码或函数,则不带对象,而如果具有必须以=或-开始的对象,则不带对象-符合Express视图系统中间JavaScript的静态缓存未缓冲的代码为条件语句等<% code %>逃逸HTML默认使用<%= code %>未逸出具有缓冲<%- code %>支持设计者喜欢的模板标签的定制过滤器支撑件包括客户端支持换行与啜<% code -%><% -%><%= code -%><%- code -%>在此处查看更多信息: https : //github.com/tj/ejs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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