作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
-6ren">
对于集合,我想使用 docpad.coffee 中定义的助手,例如
getLang: (inLang) ->
"/" + inLang + "/"
...
myCollection: ->
@getCollection("html").findAllLive().on "add", (model) ->
model.setMeta({ url: @getLang("en") + defaultUrlPartGoesHere })
最佳答案
引用 docpadConfig.templatedata.getLang()
会起作用,但如果你觉得那令人反感,请记住 docpad.coffee 只是一个标准的 NodeJS 模块(用 coffeescript 编写)。您还可以在 docpadConfig 文字对象之外定义您的函数,然后将其拉入您的 templateData(假设您需要它用于模板)并在构建集合时使用它。
例如:
# define the function outside of the config object
getLang: (inLang) ->
"/" + inLang + "/"
docpadConfig = {
templateData:
getLang: getLang # reference the previously defined function
collections:
myCollection: ->
# use the previously defined function
@getCollection("html").findAllLive().on "add", (model) ->
model.setMeta({ url: getLang("en") + defaultUrlPartGoesHere })
}
关于docpad - 如何为集合生成设置 docpad.coffee 辅助函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19247026/
我是一名优秀的程序员,十分优秀!