Meteor 无法将JavaScript变量插入Jade

Meteor 无法将JavaScript变量插入Jade,meteor,pug,Meteor,Pug,我正在尝试将普通JavaScript表达式插入到Jade文件中。但当我在代码中添加isAccepted变量时,我的应用程序不断收到错误消息。这是错误消息 你的应用程序正在崩溃。这是最新的日志 阻止启动的错误: 在构建应用程序时: jade-test.jade:jade语法错误:应为标识符、数字、字符串、>布尔值或null {{已接受?'class1':'class2。。。 ^ packages/compileJade/plugin/handler.js:44:1:无法读取未定义的属性'head'

我正在尝试将普通JavaScript表达式插入到Jade文件中。但当我在代码中添加
isAccepted
变量时,我的应用程序不断收到错误消息。这是错误消息

你的应用程序正在崩溃。这是最新的日志

阻止启动的错误:

在构建应用程序时: jade-test.jade:jade语法错误:应为标识符、数字、字符串、>布尔值或null {{已接受?'class1':'class2。。。 ^ packages/compileJade/plugin/handler.js:44:1:无法读取未定义的属性'head'(编译jade test.jade)(位于fileModeHandler)

您的应用程序有错误。正在等待文件更改

这是我的代码:

翡翠

template(name="layout")
  h1 This is layout template
  h2 This is h2 paragraph
  h3 This is h3 paragraph
   +hello

template(name="hello")
  h4 This is home template
  button Click me
  p You have click me #{counter} times.
  - var isAccepted = true
  button(class=isAccepted ? 'class1' : 'class2') I'm the right choice.
jade-test.js

if (Meteor.isClient) {
  // counter starts at 0
  Session.setDefault('counter', 0);

  Template.hello.helpers({
    counter: function () {
      return Session.get('counter');
    }
  });

  Template.hello.events({
    'click button': function () {
      // increment the counter when button is clicked
      Session.set('counter', Session.get('counter') + 1);
    }
  });

  Router.route('/', function() {
    this.render('layout');
  });
 }

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

不确定是否支持在jade中插入这样的javascript代码,您可能应该改用助手

我不认为三元表达式语法也是有效的,请再次使用helper

玉石

JS


@Saimemount,我遵循本页的指南:。其中说:所有正常的JavaScript表达式也可以正常工作:
-var authenticated=true body(class=authenticated?'authenticated':'anon')
我猜
meteor jade
只是整个jade语法的一个子集,您无论如何都不能使用此功能。非常感谢。我将使用其他语法。
template(name="hello")
  h4 This is home template
  button Click me
  p You have click me #{counter} times.
  button(class=isAccepted) I'm the right choice.
Template.hello.helpers({
  isAccepted: function(){
    var isAccepted = true;
    return isAccepted ? "class1" : "class2";
  }
});