dust.js

Dynamic Key Name in Dust.js

守給你的承諾、 提交于 2019-12-24 02:13:53
问题 I'm looking for a way to call a dynamic key in my dust template file, something like <table> {#array1} <tr> {#array2} <td>{#array1}{object.#dynAttrName#}{/array1}</td> {/array2} {/array1} </table> I would like to access to something like "object.attribute1" where 1 is the id of the current object in {array1}. (array1[n].id) Thank you for your Help ! 回答1: It can be done by adding a helper function to the context object: Context object: { get: function (chunk, context, bodies, params) { var obj

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":

How do I loop through an array passed directly to dust.js?

我与影子孤独终老i 提交于 2019-12-23 15:13:16
问题 Using the dust.js javascript templating engine, I want to pass an array directly: var templateContents; //loaded by require.js var compiled = dust.compile(templateContents, "viewElements"); dust.loadSource(compiled); dust.render("viewElements", ["bob", "joe", "sue"], function(err, out){ $('#view').html(out); }); How do I create a template file to handle an array directly? I've tried a number of things including: {.}<br> and {#.} {.} {/.} But can't seem to reference the array or the elements

Function call and checking results in DustJs

心已入冬 提交于 2019-12-23 12:23:01
问题 I am combining connect-roles with dust template ejs template have something like this syntax <% if (userCan('impersonate')) { %> <button id="impersonate">Impersonate</button> <% } %> and that in jade if userCan('impersonate') button#impersonate Impersonate How to do this in dust? {@eq key=userCan('edit data') value="true" } <td><a href='/assets/edit/{.ID_ASSET}'>Edit</a></td> <td><a href='/assets/delete/{.ID_ASSET}'>Delete</a></td> {:else} {/eq} This code get me an error Wed, 06 Jan 2016 16

How to pass partials to a Dust.js template

心已入冬 提交于 2019-12-23 03:14:37
问题 I have consulted the Dust.js GitHub page and it says that I can pass partials to templates as shown below: {@partial checkbox_title="JM"} {>toggle/} {/partial} and like this: {>toggle checkbox_title="Hi JM"/} I've tried both and neither of them worked, so I used the following: Parent: {< checkbox_title} Hi JM {/checkbox_title} {>toggle/} Child: {+checkbox_title/} The above works, except when I try to render a template using the following: dust.render("toggle", base.push({checkbox_title:

How do I implement custom rendering logic in dust.js?

我是研究僧i 提交于 2019-12-18 12:43:06
问题 I'm using dust.js to render a list of variable names that are sometimes long and contain underscores like: SUM_COUNT_LABOR_COUNTRIES_SMS_PAST The browser doesn't wrap on underscores so it can get ugly. I'd like my dust template to add a zero-width space after each underscore so the browser can wrap it. This definitely belongs in the template layer and not with the model, but I can't figure out how to properly achieve this with dust.js and it's otherwise very good principle of separating

how to use dustjs-linkedin as client side templating?

こ雲淡風輕ζ 提交于 2019-12-18 03:35:37
问题 I get the idea of server and client side templating, but dust.js confuses me a little bit. In order to use dust.js for client side templating, you need three steps: complie the template load the template render the template Right? But where do the templates come from? I saw two different methods: 1. <script> template <script> 2. <div> template </div> ... Both of them are in the DOM. Which is correct? I also notice that you can load the template via ajax, so the template won't be seen in the

What is server side rendering of javascript?

心不动则不痛 提交于 2019-12-18 01:44:09
问题 Some javascript frameworks like Dust.js claim that they ALSO support server-side rendering (in addition to client side rendering) as well. Can someone explain how does this work? My understanding is that the JS is always executed in the browser runtime. 回答1: JavaScript can be run on servers using systems like Node.js. With regard to Dust.js, a templating engine, it can generate hypertext and HTML on the server and send that content directly to the client's browser. This is typically used to

Regex remove json property

狂风中的少年 提交于 2019-12-14 00:28:34
问题 I'd like to remove a stringfied json's property based on its key wherever it is, whatever its value type is. But removing it only if its value is a string and its on the root level of the object would be nice for a beggining. I tried this: [,]{1}[\s]*?\"attrName\"[ ]*?[:][ ]*?\".*\"[^,]|\"attrName\"[ ]*?[:][ ]*?\".*\"[,]{0,1} Example : https://regex101.com/r/PAlqYi/1 but it looks a lot big to do such a simple job, what it does is ensure the comma will be removed as well, if attrName is the

Evaluate DustJS variables from jquery

孤街醉人 提交于 2019-12-13 08:28:45
问题 I want to append some HTML containing DustJS variables using jQuery. Here is what I am trying to do in jQuery: $(document).on('ready', function(){ $("tr").click(function(){ $(this).after('<tr class="row-details">\ <td></td>\ <td colspan="4">\ <table class="sortable draggable">\ <thead>\ <tr>\ <th class="col-itemName">Item Name</th>\ <th class="col-quantity">Quantity</th>\ <th class="col-rate">Rate</th>\ <th class="col-amount">Amount</th>\ </tr>\ </thead>\ <tbody>\ {#items}\ <tr>\ <td>{.item