Using dustjs-helpers with Kraken js

点点圈 提交于 2019-12-23 21:44:34

问题


I created a project using Kraken 1.0.1 with yo kraken, with template engine dustjs, but I can not use functions dustjs-helpers.

My 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 (not working helpers)

{@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 (working)

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

Only dusts core working, I add dustjs-helpers with npm. How add dustjs-helpers in my kraken project?


回答1:


Having just fought things like this for the last two days. The problem is that dust helpers clobbers any earlier defined helpers when setting up it's own. See issue: https://github.com/linkedin/dustjs-helpers/issues/72

You can try using this repo version that derives from PR mentioned in the issue 72 thread to get around it for now. https://github.com/patrick-steele-idem/dustjs-helpers Or just be very sure your helpers are defined after dustjs load and dustjs-helpers is loaded.




回答2:


On Kraken.js 1.0.3+ to add dust helpers in a krakenJS project you you need to decleare them in your config.json. By default KrakenJS does not include Dust.js helpers.

Find the section dedicated to dust in your config/confing.json and add "dustjs-helpers" entry to the "helpers" array. It should look like this if you have also dust-makara enabled:

"dust": {
    "helpers": [

        "dust-makara-helpers",
        "dustjs-helpers"


    ]
},


来源:https://stackoverflow.com/questions/24418171/using-dustjs-helpers-with-kraken-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!