我不确定为什么会收到此错误。我的 ejs“include”语法看起来正确,并且我相信我以正确的方式输入了文件路径。我查看了旧的 stackoverflow 帖子,结果一无所获。任何指示将不胜感激。
Error: Could not find matching close tag for "<%-".
at /Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:710:19
at Array.forEach (<anonymous>)
at Template.generateSource (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:700:15)
at Template.compile (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:554:12)
at Object.compile (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:368:16)
at handleCache (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:216:18)
at tryHandleCache (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:255:16)
at View.exports.renderFile [as engine] (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/ejs/lib/ejs.js:461:10)
at View.render (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/express/lib/view.js:135:8)
at tryRender (/Users/lorenzi/Desktop/startbootstrap-clean-blog/node_modules/express/lib/application.js:640:10)
<小时/>
这是我的index.js 文件
const express = require('express')
const path = require('path')
const app = new express()
const ejs = require('ejs')
const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}))
app.set('view engine','ejs')
app.set('views', '/Users/lorenzi/Desktop/startbootstrap-clean-blog/views');
app.use(express.static('public'))
app.listen(4000, ()=>{
console.log('App listening on port 4000 ...')
})
app.get('/', (req, res) => {
res.render('index');
});
app.get('/about',(req,res)=>{
res.render('about');
})
app.get('/contact',(req,res)=>{
res.render('contact');
})
app.get('/post',(req,res)=>{
res.render('post')
})
<小时/>
这是我的 index.ejs 文件中的主要包含语句
<%- include('layouts/header'); -%>
<%- include('layouts/navbar'); -%>
<%- include('layouts/footer'); -%>
<%- include('layouts/scripts'); -%>
index.ejs
<!DOCTYPE html>
<html lang="en">
<%- include('layouts/header'); -%>
<body>
<%- include('layouts/navbar'); -%>
<!-- Page Header -->
<header class="masthead" style="background-image: url('img/home-bg.jpg')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Clean Blog</h1>
<span class="subheading">A Blog Theme by Start Bootstrap</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
Man must explore, and this is exploration at its greatest
</h2>
<h3 class="post-subtitle">
Problems look mighty small from 150 miles up
</h3>
</a>
<p class="post-meta">Posted by
<a href="#">Start Bootstrap</a>
on September 24, 2019</p>
</div>
<hr>
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
I believe every human has a finite number of heartbeats. I don't intend to waste any of mine.
</h2>
</a>
<p class="post-meta">Posted by
<a href="#">Start Bootstrap</a>
on September 18, 2019</p>
</div>
<hr>
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
Science has not yet mastered prophecy
</h2>
<h3 class="post-subtitle">
We predict too much for the next year and yet far too little for the next ten.
</h3>
</a>
<p class="post-meta">Posted by
<a href="#">Start Bootstrap</a>
on August 24, 2019</p>
</div>
<hr>
<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
Failure is not an option
</h2>
<h3 class="post-subtitle">
Many say exploration is part of our destiny, but it’s actually our duty to future generations.
</h3>
</a>
<p class="post-meta">Posted by
<a href="#">Start Bootstrap</a>
on July 8, 2019</p>
</div>
<hr>
<!-- Pager -->
<div class="clearfix">
<a class="btn btn-primary float-right" href="#">Older Posts →</a>
</div>
</div>
</div>
</div>
<hr>
<%- include('layouts/footer'); -%>
<%- include('layouts/scripts'); -%>
</body>
</html>
header.ejs
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Clean Blog - Start Bootstrap Theme</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- Custom styles for this template -->
<link href="css/clean-blog.min.css" rel="stylesheet">
</head>
最佳答案
您的Syntax
错了,直接写
<%- include ('layouts/navbar.ejs') %>
ejs
没有像 -%>
这样的结束标签和 ejs
评论你可以评论为<%# (...) %>
此标签突出显示评论。
关于javascript - ejs错误: Could not find matching close tag for "<%-",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61033934/