gpt4 book ai didi

javascript - Handlebars - 期待 'OPEN_INVERSE_CHAIN' 、 'INVERSE' 、 'OPEN_ENDBLOCK' ,得到 'EOF'

转载 作者:IT老高 更新时间:2023-10-28 23:18:18 26 4
gpt4 key购买 nike

我正在试用 Handlebars ,为此我使用了以下简单模板:

<html>

<head></head>

<body>

<h1>{{title}}</h1>
<p>{{body}}</p>

{{#each list}}
<ul>
<li>{{@index}}. {{this}}</li>
</ul>
</br>
{{{htmlTag}}}

{{#if user.admin}}
<button class="launch">Launch Spacecraft</button> {{else}}
<button class="login"> Log in</button>
{{/if}}
{{!-- This is a comment --}}

</body>
</html>

我的 app.js 如下所示:

require('dotenv').config()
const express = require('express')
const logger= require('morgan')
const path = require('path')

const app = express()

app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'hbs')
app.use(logger(process.env.LOG_ENV))

app.get('/', (req, res) => {
const titel = "This is a titel"
const body = "Lorem ipsum dolor sit amen ..."
const list = ['apple', 'banana', 'vegetable']
const htmlTag = '<h2>This is an unescaped Heading</h2>'
const user = {
admin: true
}
res.render('index',{titel, body, list, htmlTag, user})
})


// Start Server
const port = process.env.APP_PORT || 8080
const host = process.env.APP_URL || '0.0.0.0'

app.listen(port, host, () => {
console.log(`Listening on ${host}:${port}/`)
})

module.exports = app

当我渲染页面时,我收到以下错误:

Error: /home/ubuntu/workspace/src/views/index.hbs: Parse error on line 20: ...}} -------------------^ Expecting 'OPEN_INVERSE_CHAIN', 'INVERSE', 'OPEN_ENDBLOCK', got 'EOF' at Object.parseError (/home/ubuntu/workspace/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:267:19) at Object.parse (/home/ubuntu/workspace/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:336:30) at HandlebarsEnvironment.parse (/home/ubuntu/workspace/node_modules/handlebars/dist/cjs/handlebars/compiler/base.js:46:43) at compileInput (/home/ubuntu/workspace/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:514:19) at ret (/home/ubuntu/workspace/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:523:18) at /home/ubuntu/workspace/node_modules/hbs/lib/hbs.js:63:19 at tryToString (fs.js:456:3) at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:443:12)

任何建议我在我的模板中做错了什么?

感谢您的回复!

最佳答案

错误状态:

Expecting (...), got EOF

地点:

  1. (...) 是它可能期望的结果
  2. EOF 是文件结尾

您缺少的是关闭 {{/each}}:

{{#each list}}
<ul>
<li>{{@index}}. {{this}}</li>
</ul>
</br>
{{{htmlTag}}} {{#if user.admin}}
<button class="launch">Launch Spacecraft</button> {{else}}
<button class="login"> Log in</button> {{/if}} {{!-- This is a comment --}}
{{/each}} <!-- HERE -->

关于javascript - Handlebars - 期待 'OPEN_INVERSE_CHAIN' 、 'INVERSE' 、 'OPEN_ENDBLOCK' ,得到 'EOF',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47300408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com