Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been expermenting with Mustache under the hood lately, so I'm interested in template implementations. It seems odd, you've chosen an odd middle-ground of "support arithmetic" and "no real heavy logic".

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?



That's a good point actually, very open to discussion on lots of things.

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


Do you know if the quote escape is still required with C# 6 interpolation?


C#6 string interpolation is glorious, but if you use the multiline

    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.


Scala seems to do what you want:

    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.


Neat! With facilities like that, Id be tempted to skip templating libraries altogether and just have a normal interface for templates and use the regular string expressions... Unless I needed then internationalized, and that's where Mustache shines, IMHO.


F# can have quotes inside triple-quoted string like Scala, sans interpolation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: