samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
828 stars 129 forks source link

How to implement an OR #136

Open Samyssmile opened 1 year ago

Samyssmile commented 1 year ago

I want to achieve something like this pseudecode

if(a != null || b !=null) peter else{ jackson }

Ist it possible with the newest version?

agentgt commented 7 months ago

Ist it possible with the newest version?

OOB, No. The above might not even possible with Handlebars.

I recommend decorating the model (e.g. wrapping) or using JMustache Lambdas which are very powerful as they allow stack access.

I'll add code later but you could make a generic Condition builder lambda.

{{#a}}
{{#cond}}
{{#or}}
{{#b}}
{{#test}}

Finally do your or logic here.

{{/test}}
{{/b}}
{{/or}}
{{/cond}}
{{/a}}

But I imagine that might be a little too verbose for your liking so I think decorating is your best option.