句柄在编译模板时解析错误

时间:2014-07-23 05:43:07

标签: handlebars.js

我在使用Windows CMD编译把手模板时遇到错误。我的车把客户端和服务器都是@ 1.3.0请帮我识别我出错的地方

dashboard.handlebars代码 -

<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2" style="text-align:center;">
    <li>

        <div class="chart" data-percent="{{#getPercent reward_point.point_achived reward_point.point_available}}">
            <span>{{#getPercent reward_point.point_achived reward_point.point_available}}%</span>
            <span style="font-size:.5em;display:inline-block;">{{reward_point.point_achived}}</span>
            <span style="font-size:.5em; color:#005390; display:inline-block;">/{{reward_point.point_available}} RP</span>
        </div>
    </li>
    <li>

        <div class="chart" data-percent="{{#getPercent calorie_budget.point_achived calorie_budget.point_available}}">
            <span>{{#getPercent calorie_budget.point_achived calorie_budget.point_available}}</span>
            <span style="font-size:.5em;display:inline-block;">{{calorie_budget.point_achived}}</span>
            <span style="font-size:.5em; color:#005390; display:inline-block;">/{{calorie_budget.point_available}} cal</span>
        </div>
    </li>
    <li>

        <div class="chart" data-percent="{{#getPercent 30_day_challenge.point_achived 30_day_challenge.point_available}}">
            <span>{{#getPercent 30_day_challenge.point_achived 30_day_challenge.point_available}}</span>
            <span style="font-size:.5em;display:inline-block;">{{30_day_challenge.point_achived}}</span>
            <span style="font-size:.5em; color:#005390; display:inline-block;">/{{30_day_challenge.point_available}} complete</span>
        </div>
    </li>
    <li>

        <div class="chart" data-percent="{{#getPercent physical_activity.point_achived physical_activity.point_available}}">
            <span>{{#getPercent physical_activity.point_achived physical_activity.point_available}}</span>
            <span style="font-size:.5em;display:inline-block;">{{physical_activity.point_achived}}</span>
            <span style="font-size:.5em; color:#005390; display:inline-block;">/{{physical_activity.point_available}} min</span>
        </div>
        </li>
</ul>
cmd中的

错误 -

Error: Parse error on line 34:
</ul>      </li>
----------------------^
Expecting 'CONTENT', 'COMMENT', 'OPEN_BLOCK', 'OPEN_INVERSE', 'OPEN_ENDBLOCK', '
OPEN', 'OPEN_UNESCAPED', 'OPEN_PARTIAL', got 'EOF'
    at Object.parseError (C:\Users\User\AppData\Roaming\npm\node_modules\handleb
ars\dist\cjs\handlebars\compiler\parser.js:107:11)
    at Object.parse (C:\Users\User\AppData\Roaming\npm\node_modules\handlebars\d
ist\cjs\handlebars\compiler\parser.js:159:22)
    at HandlebarsEnvironment.parse (C:\Users\User\AppData\Roaming\npm\node_modul
es\handlebars\dist\cjs\handlebars\compiler\base.js:12:17)
    at precompile (C:\Users\User\AppData\Roaming\npm\node_modules\handlebars\dis
t\cjs\handlebars\compiler\compiler.js:435:17)
    at HandlebarsEnvironment.hb.precompile (C:\Users\User\AppData\Roaming\npm\no
de_modules\handlebars\dist\cjs\handlebars.js:22:12)
    at processTemplate (C:\Users\User\AppData\Roaming\npm\node_modules\handlebar
s\bin\handlebars:188:78)
    at C:\Users\User\AppData\Roaming\npm\node_modules\handlebars\bin\handlebars:
194:3
    at Array.forEach (native)
    at Object.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\handle
bars\bin\handlebars:193:8)
    at Module._compile (module.js:456:26)

1 个答案:

答案 0 :(得分:17)

你正在调用你的getPercent - 助手,前面有一个哈希值,这使得它成为一个块语句,然后需要使用{{/getPercent}}来关闭它。由于不需要将它作为块,您可能只需从模板中删除哈希值。

<div class="chart" data-percent="{{getPercent reward_point.point_achived reward_point.point_available}}">
  <span>{{getPercent reward_point.point_achived reward_point.point_available}}%</span>
  <span style="font-size:.5em;display:inline-block;">{{reward_point.point_achived}}</span>
  <span style="font-size:.5em; color:#005390; display:inline-block;">/{{reward_point.point_available}} RP</span>
</div>