ejs错误:找不到“

问题描述 投票:-1回答:1

我不确定为什么会收到此错误。我的ejs“包含”语法看起来正确,并且我相信我以正确的方式输入了文件路径。我查看了旧的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语句

  <%- include('/Users/lorenzi/Desktop/startbootstrap-clean-blog/views/layouts/header'); -%>

  <%- include('/Users/lorenzi/Desktop/startbootstrap-clean-blog/views/layouts/navbar'); -%>

<%- include('/Users/lorenzi/Desktop/startbootstrap-clean-blog/views/layouts/footer'); -%> 

  <%- include('/Users/lorenzi/Desktop/startbootstrap-clean-blog/views/layouts/scripts'); -%>

index.ejs

<!DOCTYPE html>
<html lang="en">

  <!--  The include call receives a path relative to the template. So, since the path of header.ejs is in
        views/layouts/header.ejs and index.ejs is in ./views/index.ejs, we specify include('layouts/header'). 
        We use the raw output tag <%- with include to allow rendering of the HTML output.
  -->
  <%- 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 &rarr;</a>
        </div>
      </div>
    </div>
  </div>

  <hr>

  <%- include('layouts/footer'); -%> 
  <%- include('layouts/scripts'); -%>

</body>

</html>


javascript node.js express ejs template-engine
1个回答
0
投票
We use the raw output tag <%- with include

以上<%-没有匹配的结束标记。

EJS不会解析HTML注释。

© www.soinside.com 2019 - 2024. All rights reserved.