mustache-sharp
mustache-sharp copied to clipboard
Calculation in identifier
Is it possible to do expressions in identifier like {{num1 * num2}}. Adding this feature would make this library more powerful like xslt transformation.
Thanks
Sharing for posterity:
The facility to do this exists on the C# side but that doesn't help if you want to do it in the tags. Currently, #set
doesn't allow you to set the value. The solution could be a number of things.
- Some combination of allowing set to set a value also
#set value 1
and then custom tags that perform the operations (perhaps an AddTagDefinition, etc.). That requires new tags for every operation (+, -, /, *) and somewhat boxes you in with the number of parameters accepted. - My idea (that I might try out) is to create an
eval
TagDefinition that uses a scripting engine to evaluate the text (Lua or JavaScript being my initial thoughts, either through MoonSharp, Jint or Topaz). You could share the scopes state with the scripting engine and then do "{{#eval}}num1 * num2{{/eval}}" etc.