Can the {@size} helper be used inside the {@math} helper in dust?

Here's a snippet of code:

{@math key="{@size key=result/}" method="subtract" operand="3"/}

The above code is throwing " Syntax: This is the expected end tag for eq, but it was not found. "

Is there any other way to achieve the above operation in dustjs?

+3


source to share


1 answer


Dust does not allow using a helper as the value of the passed parameter.

In general, once you start nesting helpers, you should ask if you are nesting too much logic in your templates and not in the context - this is what Dust is trying to enforce with relatively strong constraints.

You can use a contextual helper to pull this logic out of your template, for example:

{#overflow key=results}...and {.} more!{/overflow}

      



Notice how the logic has been removed from the template. Now you are not a hard and fast business rule.

Add the helper overflow

to the context:

{
  "results": [ ... ],
  "overflow": function(chunk, context, bodies, params) {
    var results = context.resolve(params.key);
    return results.length - 3;
  }
}

      

0


source







All Articles