by Pxtl · 10y ago · 0 comments
Having played with the subject a few times, I've come to the general feeling that it's best to choose a hard line on one side or the other - either the mustache "pure logicless" or just do straight string interpolation (assuming the language provides a good syntax for multi-line string interpolation - C# almost does except that you have to escape all your quotes. Dunno if other languages to better).
Any particular reason why you chose to support some logic instead of none or all?
The main usecase is that I need quite often to do something like +1 or *10 and having to write {{count|add:1}} feels really wrong to me.
Maybe having only simple math would be better?
Opened https://github.com/Keats/tera/issues/22 if people want to write some input
var myString = $@"
Hey, string interpolation is nifty.
Look ma, no { this.Hands.ToString().ToUpper() }
More text.
But this is a ""quote"". It's ""ugly"" isn't it?
";
As you can see, you need to double your double quotes to escape them. Almost perfect. You can even nest string interpolations to do next template stuff with functional-programming loops and whatnot. val str = s"""
Tripe quoted string interpolation
Allows for $variables and ${method.foo(bar)}
Mixed with "quotes"
"""
Can also use double quoted string interpolation for inline/one-liners where embedded quotes above aren't needed.