【问题标题】:templateData variables return undefined from helper function (docpad.coffee configuration file)templateData 变量从辅助函数返回 undefined(docpad.coffee 配置文件)
【发布时间】:2013-07-03 17:14:17
【问题描述】:

这是我的configuration file

docpadConfig = {
    templateData:
        site:
            title: 'hello docpad'

        getTitle: ->
            @site.title

        getString: ->
            'just a string'
}

# Export the DocPad Configuration
module.exports = docpadConfig

当我做title= site.title 时,它从玉器布局中呈现正常。当我尝试调用辅助函数 title= getTitle() 时,控制台会输出以下内容:

error: An error occured:
ReferenceError: /Volumes/Data/project/am/lab/docpad/hello_docpad/src/layouts/default.html.jade:21
    19|
    20|     //- Our site title and description
  > 21|     title= getTitle()
    22|
    23|     //- Output DocPad produced meta elements
    24|     != getBlock('meta').toHTML()

site is not defined
    at docpadConfig.templateData.getWat (/Volumes/Data/project/am/lab/docpad/hello_docpad/docpad.coffee:10:16)
    at eval (eval at <anonymous> (/Volumes/Data/project/am/lab/docpad/hello_docpad/node_modules/docpad-plugin-jade/node_modules/jade/lib/jade.js:170:8), <anonymous>:47:64)

看起来我无法从辅助函数内部访问站点对象。

我确定我遗漏了一些琐碎的东西,也许需要一个插件来解决这个问题......在这里找不到“wat”是错误的。

【问题讨论】:

    标签: node.js scope coffeescript docpad


    【解决方案1】:

    我在docpad skeleton 中找到了针对类似问题的解决方案。这与 Jade 预处理器中的 bug 有关。

    更新到"docpad-plugin-jade": "~2.4.1" 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 2017-03-27
      • 2016-11-25
      • 2011-10-17
      • 1970-01-01
      • 2011-08-24
      • 2021-10-12
      相关资源
      最近更新 更多