mustache-sharp icon indicating copy to clipboard operation
mustache-sharp copied to clipboard

Calculation in identifier

Open last-Programmer opened this issue 6 years ago • 1 comments

Is it possible to do expressions in identifier like {{num1 * num2}}. Adding this feature would make this library more powerful like xslt transformation.

Thanks

last-Programmer avatar Sep 13 '18 16:09 last-Programmer

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.

  1. 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.
  2. 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.

blakepell avatar May 17 '23 15:05 blakepell