I am getting a JSON from contollers and on the basisi of value of this JSON i want to set key in my dust file, so that this key will access data from properties file.
For example I am getting "step" from controllers.
{
step: step1
}
I want to set key in dust:
{@pre type="content" key="{step}"/}
and in properties I have
step1=This is dynamic key
step2=print this
but i am getting step1 in dust. its not accesing the values of keys. Can anyone suggest me how to display values associated with keys in this situtaion.
{@pre type="content" key=step/}
when step is a variable. To set a string, ex: 'stackoverflow', try:
{@pre type="content" key="stackoverflow"/}
Is this your own pre helper?
You need to change the behavior of the helper to adjust what it does with the param.
function(chunk, context, bodies, params) {
// Assuming I have {@pre key="{step}" /}
params.key; // <== this will be a Dust function that, when run, returns "step1"
dust.helpers.tap(params.key, chunk, context); // <== the string "step1"
context.get(dust.helpers.tap(params.key, chunk, context)); // <== the string "This is dynamic key"
}
You want to evaluate the parameter, then get the corresponding key from the context, so you want the third form.
dust.helpers.tap requires the dustjs-helpers addon library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With