samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
834 stars 128 forks source link

Formatter doesn't get the correct type #88

Closed osrl closed 6 years ago

osrl commented 7 years ago

Formatter gets the date as String when using like this:

{{#date}}
    <span class="date">{{date}}</span>
{{/date}}

Is there a way to do a null check without calling format?

samskivert commented 6 years ago

Apologies for not getting back to you on this in a timely fashion.

I'm not really sure what you are trying to do here. Assuming date is a property that either maps to null or java.util.Date object, then I think what you want is:

{{#date}}
    <span class="date">{{.}}</span>
{{/date}}

which will omit the section if date is null, otherwise it will render the section once, with the date in place of {{.}}.