0
{#access_map.modifiable_objects}
    <div class='col-md-2 col-xs-4'> 
        <i class="fa {icon}"> </i>
        <span> {name} </span>
        {#mods}
            {>"dust/admin/helpers/form-checkbox" name="{form_name}" label="{display_name}" value="{value}"/}
            <p> {data.powers.{id}} </p>
        {/mods}
    </div>
{/access_map.modifiable_objects}

I have the following code above.

Notice how {data.powers.{id}} is used. My real intention is to do something like : data.powers[<id_name_here>] or data.powers.<id_name_here>;

However, it renders a string. The scope of ID however, SURELY reaches that part where I used it. Any suggestions?

2 Answers 2

1

Dust doesn't currently support variable substitution natively. You could write a small helper to do what you want instead.

dust.helpers.get = function(chunk, context, bodies, params) {
  var key = context.get(context.resolve(params.key));
  return chunk.reference(key, context);
};

Then you can use the helper like this:

{@get key="data.powers.{id}" /}

If id were foo, this would output the value of data.powers.foo.

Sign up to request clarification or add additional context in comments.

Comments

1

Sorry I got the answer.

It's supposed to be {data.powers[id]} and not data.powers[{id}]; It works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.