sachatrauwaen / OpenContent

Structured Content editing for DNN (Dotnetnuke)
46 stars 25 forks source link

New Serverside Handlebars Maths Expression Helper #142

Open robert-m opened 3 years ago

robert-m commented 3 years ago

The current maths expression helpers are very limiting to just 2 numbers. It would be great if we could string together a series of intergers with different operators within the same HB helper to get a value if achievable like the examples below.

Simple Examples Adding {{math results.game1 + results.game2 + results.game3}}

Adding & Dividing Example 1 {{math results.game1 + results.game2 + results.game3 / 24}}

Adding & Dividing Example 2 {{math results.game1 + results.game2 + results.game3 / @index}}

Adding & Dividing & Multipling Example {{math results.game1 + results.game2 + results.game3 / 100 * settings.rounds}}

Timo-Breumelhof commented 3 years ago

@robert-m Did you find any existing Handlebars scripts (JS) that support this?

robert-m commented 3 years ago

@Timo-Breumelhof I haven't looked into it too much, but from my preliminary research I found this as a possible starting point. https://github.com/mrhanlon/handlebars-math-helper

Another way to get this implemented would be to use Handlebars Subexpressions? https://handlebarsjs.com/guide/expressions.html#subexpressions