Jade中嵌套的Mixin会导致非法令牌错误

时间:2015-10-26 22:14:51

标签: javascript node.js pug mixins

我有一个复杂的Jade模板,我简化了这个问题。我正在考虑使用动态嵌套mixin,它根据我传递的字符串的值更改输入的属性。我必须使用mixin作为输入,所以不幸的是,对我来说没有这个选项。我在Unexpected token ILLEGAL的行上收到了错误+input_mixin(...

mixin name_of_mixin(type)
    - if type == 'multiple'
        - var name = '{{:#index}}'
    - else if type == 'old'
        - var name = 'old'
    - else
        - var name = 'normal'
    +input_mixin(#{name})

1 个答案:

答案 0 :(得分:0)

通过查看玉器文档,我的建议是执行以下操作来摆脱 非法令牌错误 ,实际上有点过分夸张。

- var name = ""
mixin input_mixin(name, name)
  input(name=name)&attributes(attributes)= name

mixin name_of_mixin(type)
    if type == 'multiple'
        - name = '{{:#index}}'
    else if type == 'old'
        - name = 'old'
    else
        - name = 'normal'
+name_of_mixin('foo')
+input_mixin(- name, name)(placeholder='plaeceholder value')

jaruesink提出了以下简化的解决方案,似乎工作正常。我猜主要问题是mixin-call的缩进和条件语句前面的连字符。

- var name = ""
mixin input_mixin(name)
  input(name=name)&attributes(attributes)

mixin name_of_mixin(type)
    if type == 'multiple'
        - name = '{{:#index}}'
    else if type == 'old'
        - name = 'old'
    else
        - name = 'normal'
+name_of_mixin('foo')
+input_mixin(name)(placeholder='placeholder value')