【问题标题】:Using dustjs-helpers with Kraken js在 Kraken js 中使用dustjs-helpers
【发布时间】:2015-09-23 19:53:16
【问题描述】:

我使用 Kraken 1.0.1 和 yo kraken 创建了一个项目,带有模板引擎dustjs,但我不能使用函数dustjs-helpers。

我的 config.json:

"express": {
    "view cache": false,
    "view engine": "dust",
    "views": "path:./public/templates"
},

"view engines": {
    "dust": {
        "module": "engine-munger",
        "renderer": {
            "method": "dust",
            "arguments": [
                { "cache": false},
                {
                    "views": "config:express.views",
                    "view engine": "config:express.view engine",
                    "specialization": "config:specialization",
                    "i18n": "config:i18n"
                }
            ]
        }
    }
}

template.dust(不工作的助手)

{@if cond="1<2"}
   <div>  x is less than y and b == c and either e or f exists in the output </div> 
 {:else}
   <div> x is >= y </div>
 {/if}

template2.dust(工作)

        {?messages}
            {#messages}
                <div data-alert class="alert-box info radius">
                  {.}
                  <a href="#" class="close">&times;</a>
                </div>
            {/messages}
        {/messages}

只有灰尘核心工作,我用 npm 添加了dustjs-helpers。如何在我的 kraken 项目中添加dustjs-helpers?

【问题讨论】:

    标签: node.js dust.js kraken.js


    【解决方案1】:

    在过去的两天里刚刚经历了这样的事情。问题是灰尘助手在设置它自己的时候会破坏任何先前定义的助手。见问题:https://github.com/linkedin/dustjs-helpers/issues/72

    您现在可以尝试使用源自问题 72 线程中提到的 PR 的这个 repo 版本来解决它。 https://github.com/patrick-steele-idem/dustjs-helpers 或者只是非常确定你的助手是在加载dustjs和加载dustjs-helpers之后定义的。

    【讨论】:

    • 没有提供可以在我的答案中找到的正确解决方案。
    【解决方案2】:

    在 Kraken.js 1.0.3+ 上,要在 krakenJS 项目中添加灰尘助手,您需要在 config.json 中清除它们。默认情况下,KrakenJS 不包含 Dust.js 助手。

    在 config/confing.json 中找到专门讨论灰尘的部分,并将“dustjs-helpers”条目添加到“helpers”数组中。如果您还启用了dust-makara,它应该看起来像这样:

    "dust": {
        "helpers": [
    
            "dust-makara-helpers",
            "dustjs-helpers"
    
    
        ]
    },
    

    【讨论】:

      猜你喜欢
      • 2015-02-24
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多