I would like to add a value to dust.js as follows:
this is x+1 : {{x}+1} //does not work :'(
What I know, I can do it with an assistant (terribly detailed)
this is x+1 : {@math key="x" method="add" operand="1" /}
What can I live with (but not happy)
But what about when I want to insert 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
Can this be done? I am tempted to try and fix this in the main library because it is very annoying to me.
What other ways to do this? Creating temporary variables (for example, {xplus1})? My real solution is to move any / all logic to helpers - I write a lot of helpers.
update:
I wrote a helper that can create variables with scope. This seems like a clean way to do it.
{@eval xplus1="{x} + 1"} ... scope where x = x+1 this is x+1 : {xplus1} {/eval}
He is currently using JavaScript eval, but I am considering using a JS math library like JavaScript Expression Evaluator or math.js
source share