把手 - 期待' OPEN_INVERSE_CHAIN'' INVERSE',' OPEN_ENDBLOCK',得到了EOF'

时间:2017-11-15 06:02:26

标签: javascript node.js express handlebars.js

我正在尝试把手,我正在使用以下简单的模板:

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 如下所示:

// init controller
var controller = new ScrollMagic.Controller();

// loop through all elements
$(".fade-in").each(function() {
  var jh1 = $(this).find("h1");
  var jspan = $(this).find("span");
  var tl = new TimelineMax();

  tl
    .from(
      jh1,
      0.5,
      { autoAlpha: 0, scale: 0.5, x: 300, ease: Linear.easeNone },
      "x"
    )
    .from(
      jspan,
      0.5,
      {
        autoAlpha: 0,
        scale: 0.5,
        x: -300,
        color: "red",
        ease: Linear.easeNone
      },
      "x"
    );

  // build a scene
  var scene = new ScrollMagic.Scene({
    triggerElement: this,
    offset: 10,
    triggerHook: 0
  })
    .setTween(tl) // trigger a TweenMax.to tween
    .addIndicators()
    .addTo(controller);
});

当我渲染页面时,出现以下错误:

  

错误:/home/ubuntu/workspace/src/views/index.hbs:在线解析错误   20:       ...}}       ------------------- ^       期待&#39; OPEN_INVERSE_CHAIN&#39;,&#39; INVERSE&#39;,&#39; OPEN_ENDBLOCK&#39;,得到了EOF&#39;           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)           在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           在tryToString(fs.js:456:3)           在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:443:12)

我的模板中有什么建议我做错了吗?

感谢您的回复!

3 个答案:

答案 0 :(得分:18)

错误状态:

  

期待(...),得到了EOF

其中:

  1. (...)是它可能期待的东西
  2. EOF是文件结束
  3. 您缺少的是关闭{{/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 -->
    

答案 1 :(得分:4)

这始终是因为没有关闭{{each}}{{if}}或任何其他控制语句,但它不能被像{{1}这样的未关闭的html标记所取代},<div>或任何其他html标记。

答案 2 :(得分:0)

这是因为您错过了关闭{{#each}}。 在循环末尾添加{{/each}}