dust.js

How to pass partials to a Dust.js template

为君一笑 提交于 2019-12-06 15:18:28
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:"hhhhhh"}), function(err, html) { console.log(html); }); Aim: to override the block in the child template

How to run or condition in Dust template

只谈情不闲聊 提交于 2019-12-06 06:57:13
问题 I am using "dustjs-helpers": "1.6.0" , with "dustjs-linkedin": "^2.6.0" . In my template I need to check an OR condition like if( cherry === true || berry === true) path/to/template1/ else path/to/template2/ How do I accomplish this with the Dust helpers? 回答1: Because you're testing two different variables, you'll need two different truth tests. You can either put this logic into your template, or into a small helper. I'll show you both ways. Let's assume that your context looks like this: {

Dust.js output JSON key

你离开我真会死。 提交于 2019-12-05 07:07:48
问题 With dust.js, is it possible to output the JSON key ? i.e. How do I output the key "name" and "profile" without hard-coding them in my template? { name: "Foo", profile: { name: "Bar" } } Final text, JSON key name and profiles not barcoded. name Foo profile - name - Bar 回答1: sure you can. define a section like so: {@keyvalue:cont} {key} - {value} {/keyvalue} then redefine the JSON context like so: cont:{ name: "Foo", profile: "Bar" //I'm simplifying this a bit for the sake of this example }

Why should we wrap our templates inside script blocks?

只愿长相守 提交于 2019-12-05 05:01:21
Background All the JS template engines recommend putting your template text inside script blocks like so: <script id="peopleTemplate" type="text/template"> {#people} <div class="person">Name: {firstName} {lastName}</div> {/people} </script> but many developers (understandably) dislike this because they lose HTML syntax highlighting in their code editor inside the script block. I've seen the workarounds like this: Keep correct HTML syntax highlighting in <script> "text/html" templates . This question is not asking about workarounds. I know one danger is that web browsers will attempt to fix

Is there a way to do more than one level of inheritance value overrides with dust.js?

ぃ、小莉子 提交于 2019-12-05 00:51:56
问题 I'm using dust templates and one aspect of the design has been bugging me. This makes me wonder if I'm "doing it wrong" so I thought I would ask S.O. Is there a way to create multiple-level inheritance in dust.js with blocks and inline partials? Lets say you have a base template with layout, an inheriting template that overrides some content, and then yet another template inheriting from that template that wishes to selectively override some content. Normally I would imagine it works by the

How to run or condition in Dust template

狂风中的少年 提交于 2019-12-04 14:03:36
I am using "dustjs-helpers": "1.6.0" , with "dustjs-linkedin": "^2.6.0" . In my template I need to check an OR condition like if( cherry === true || berry === true) path/to/template1/ else path/to/template2/ How do I accomplish this with the Dust helpers? Because you're testing two different variables, you'll need two different truth tests. You can either put this logic into your template, or into a small helper. I'll show you both ways. Let's assume that your context looks like this: { "cherry": false, "berry": true } Template method This method requires dustjs-helpers >= 1.6.2 You'll have to

Dust if condition

强颜欢笑 提交于 2019-12-04 02:44:27
I'm having trouble with a dust if condition. I have a partial that points to 2 different dust templates depending on the Country code {>"receipt/merchantInfo/merchantInfo_{countryCode}"/} I'm trying to make an if else condition that will figure out if the {countryCode} is US. Example: {@if cond="'{countryCode}' == 'US'"} <p>is country code US</p> {:else} <p>is NOT country code US</p> {/if} This isn't working. Anyone have an idea where I went wrong with this? The @if helper has been deprecated because of a potential security hole (it uses eval on the condition). I would recommend using the @eq

Dust.js output JSON key

≡放荡痞女 提交于 2019-12-03 21:41:56
With dust.js , is it possible to output the JSON key ? i.e. How do I output the key "name" and "profile" without hard-coding them in my template? { name: "Foo", profile: { name: "Bar" } } Final text, JSON key name and profiles not barcoded. name Foo profile - name - Bar asyraf9 sure you can. define a section like so: {@keyvalue:cont} {key} - {value} {/keyvalue} then redefine the JSON context like so: cont:{ name: "Foo", profile: "Bar" //I'm simplifying this a bit for the sake of this example } this is so that the context for the keyvalue section above gets constrained to only 'cont'. then you

Is there a way to do more than one level of inheritance value overrides with dust.js?

女生的网名这么多〃 提交于 2019-12-03 16:13:11
I'm using dust templates and one aspect of the design has been bugging me. This makes me wonder if I'm "doing it wrong" so I thought I would ask S.O. Is there a way to create multiple-level inheritance in dust.js with blocks and inline partials? Lets say you have a base template with layout, an inheriting template that overrides some content, and then yet another template inheriting from that template that wishes to selectively override some content. Normally I would imagine it works by the last inheriting template providing the final overriding values. The inline partial syntax, however,

Is it possible to render dust.js templates synchronously?

让人想犯罪 __ 提交于 2019-12-03 06:57:23
问题 I am trying to write an adapter for a client-side HTML/JS templating system to use dust.js under the hood. Unfortunately the API expects render operations to occur synchronously: the rendered output should be returned from the render() call. Dust.js is asynchronous and passes render output to a callback function. Is there any way to work around this, either in the Dust APIs or through some crazy Javascript hack? 回答1: DustJS is only going to execute things asynchronously when the resources it