Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dynamic keys in dust to map content in properties file

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.

like image 716
user3386363 Avatar asked Dec 06 '25 08:12

user3386363


2 Answers

{@pre type="content" key=step/}

when step is a variable. To set a string, ex: 'stackoverflow', try:

{@pre type="content" key="stackoverflow"/}
like image 189
myusuf Avatar answered Dec 08 '25 02:12

myusuf


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.

like image 25
Interrobang Avatar answered Dec 08 '25 02:12

Interrobang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!