Question: I'd like to be able to add a value in dust.js like this:

```
 this is x+1 : {{x}+1} //does not work  :'(

```

Which I know I can do it with a helper (horrendously verbose)

```
 this is x+1 : {@math key="x" method="add" operand="1" /}

```

Which I can live with (but not happy)

But what about when I want to nest a parameter?

```
 this is x+1+1 : {@math key='{@math key="x" method="add" operand="1" /}' method="add" operand="1" /} // no dice and wins ugly code prize!

 this is x+1+1 : {@math key='x' method="add" operand="1"} {@math key="selectKey" method="add" operand="1" /} {/math}  //still no dice - btw selectKey is an output variable for the @math helper

```

Is it possible to do this? I'm tempted to try and patch this in the core lib because it is annoying me so much. 

What other ways are there to do this? Creating temporary variables (ie {xplus1})? My current solution is to move any/all logic to helpers - I am writing a lot of helpers.

---

update:

I have written a helper that can create scoped variables. This seems like a clean way to do it. 

```
   {@eval xplus1="{x} + 1"}

    ... scope where x = x+1
     this is x+1 : {xplus1} 

   {/eval} 

```

Right now it is using JavaScript eval, but I'm considering using a JS math lib like [JavaScript Expression Evaluator](http://silentmatt.com/javascript-expression-evaluator/) or [math.js](http://mathjs.org/)

Answer: 
In addition to Tom's solution, here is another implementation of an `eval` helper that evaluates the containing block.

For example, if you have a variable `a = 5` and `b = 10` in your context,

```
{@eval}{a} + {b} + 100{/eval}

```

would be rendered as `115`.

You can also compose those evals:

```
{@eval}{a} + {b} + {@eval}{a} + {b} + 100{/eval}{/eval} //Would render 130

```

Here is the code:

```
dust.helpers.eval = function(chunk, context, bodies) {
    var expression = '';
    chunk.tap(function(data) {
        expression += data;
        return '';
    }).render(bodies.block, context).untap();
    chunk.write(eval(expression));
    return chunk;
}

```
here is 'eval' - i'm afraid i didn't test it, but it should work. add this in <https://github.com/linkedin/dustjs-helpers/blob/master/lib/dust-helpers.js> along with the other helpers.

```
"eval" : function( chunk, context, bodies, params ){
        var body = bodies.block, exp, param, exps = {};        
        for(param in params){
          if(Object.hasOwnProperty.call(params,param)){
               exp = dust.helpers.tap(param, chunk, context);               
               exps[param]=eval(exp);            
          }
        }
        if(body) {
         context = context.push(exps);
         return chunk.render( bodies.block, context );
        }
        else {
         _console.log( "Missing body block in the eval helper!" );
         return chunk;
        }
    };

```

you must include dust-helpers.js as well as the main dust js file.