为什么Node JS无法识别EJS的结尾括号 [英] Why node js is not recognizing ending brackets for ejs
本文介绍了为什么Node JS无法识别EJS的结尾括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用express和ejs在节点js中创建图片库以下是我的app.js的代码
var express = require('express');
var app = express();
app.set("view engine", "ejs");
app.get("/", function(req, res){
res.render("welcome");
});
app.get("/campground", function(req, res){
var campground = [
{name : "Salmon Creek", image :
"http://www.onguma.com/uploads/1/1/7/5/117537555/201604-aoba-
935_2_orig.jpg"},
{name : "Granite Hill", image : "https://d2y0su6ixv655t.cloudfront.net/wp-
content/uploads/2014/07/16115316/BR15102803V_069.jpg"},
{name : "Mountain Goat's Rest", image :
res.render("campground", {campground:campground});
});
app.listen(5000, function(){
console.log("Server has been started");
})
现在是露营地,以下是ejs文件
这是露营地页面
Now for campground the following is the ejs file
This is the campground page
<% campground.forEach(function(camp){ %>
<div>
<h4><%= camp.name %></h4>
<img src="<%= camp.image %>">
</div>
<% >})%>
<a href="/">Home Page</a>
节点让%>混淆了上一行中图像标签中的img标签括号
Node is confusing %> for img tag brackets in image tag in above line
并产生以下错误
SyntaxError: Unexpected token > in
/projects/Backendt/YelpCamp/views/campground.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass async: true as an
option.
at new Function (<anonymous>)
at Template.compile
(/projects/Backendt/YelpCamp/node_modules/ejs/lib/ejs.js:618:12)
at Object.compile
(/projects/Backendt/YelpCamp/node_modules/ejs/lib/ejs.js:389:16)
at handleCache
(/projects/Backendt/YelpCamp/node_modules/ejs/lib/ejs.js:212:18)
at tryHandleCache
(/projects/Backendt/YelpCamp/node_modules/ejs/lib/ejs.js:251:16)
at View.exports.renderFile [as engine]
(/projects/Backendt/YelpCamp/node_modules/ejs/lib/ejs.js:482:10)
at View.render
(/projects/Backendt/YelpCamp/node_modules/express/lib/view.js:135:8)
at tryRender
(/projects/Backendt/YelpCamp/node_modules/express/lib/application.js:640:10)
at Function.render
(/projects/Backendt/YelpCamp/node_modules/express/lib/application.js:592:3)
at ServerResponse.render
(/projects/Backendt/YelpCamp/node_modules/express/lib/response.js:1008:7)
**请告诉我上述情况下如何使用ejs代码插入图片
**Plz tell me how to insert image using ejs code for above case
推荐答案
此:
<% >})%>
应该是这样
<% })%>
这篇关于为什么Node JS无法识别EJS的结尾括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文