Is it possible to check the array size or check if the first element exists?

394 views
Skip to first unread message

Vinícius Carneiro

unread,
May 17, 2018, 12:22:58 PM5/17/18
to mustache.java
I would like to do something like:

{{#id_equipe.0}}
AND
(
{{#id_equipe}}
id_equipe
= {{.}} OR
{{/id_equipe}}
1=2)
{{/id_equipe.0}}

input:
{
 
"id_equipe":[55, 52]
}

the result would be:

AND( id_equipe= 55 OR id_equipe= 52 OR 1=2


Vinícius Carneiro

unread,
May 17, 2018, 12:31:13 PM5/17/18
to mustache.java
I tried here http://mustache.github.io/#demo and it works, but I am using  this version:

<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.9.5</version>
<scope>compile</scope>
</dependency>

And did not work :/ the result is empty

Sam Pullara

unread,
May 17, 2018, 4:10:10 PM5/17/18
to mustac...@googlegroups.com
The Java version of mustache doesn't have that behavior as it isn't in the specification. I recommend having a view class that sits between the template and your data[1]. However, if you want to use that syntax you can steal the code in this test:


It will automatically wrap your arrays with a map interface that lets you look up elements by numerical offset.


--
You received this message because you are subscribed to the Google Groups "mustache.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hòa Lê

unread,
May 21, 2018, 12:27:03 AM5/21/18
to mustache.java
You can wrapper your list with DecoratedCollection.
     public List<TripImage> getExpImage() {
        return expImage;
    }

    public void setExpImage(List<TripImage> expImage) {
        this.expImage = expImage;
    }

    public DecoratedCollection<TripImage> getExtImage() {
        if(this.expImage!=null) {
            return new DecoratedCollection<>(this.expImage);
        }
        return null;
    }

and in view:
 {{#trip}}{{#extImage}}

{{index}}
{{#value}}{{imageId}}{{/value}}
                                          

{{/extImage}}{{/trip}}

or {{first}} {{last}}

Vào 23:22:58 UTC+7 Thứ Năm, ngày 17 tháng 5 năm 2018, Vinícius Carneiro đã viết:

Sam Pullara

unread,
May 21, 2018, 3:56:11 AM5/21/18
to mustac...@googlegroups.com
Thanks Hòa, forgot that was included.

Sam


Devaraj Gurikar

unread,
Jun 26, 2018, 5:51:15 AM6/26/18
to mustache.java
Sam,

how to do similar check in Play Scala project??

I tried list.size in java it works but not in Scala project.

Regards
Devaraj 
To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava...@googlegroups.com.

Sam Pullara

unread,
Jun 26, 2018, 11:53:51 AM6/26/18
to mustac...@googlegroups.com
I think in Scala there is a way to get a normal Java list out of a Scala one and then wrap that. But you could also just write your own decorator that does that work.


Sam


To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages