Expansions of different objects of the same type

33 views
Skip to first unread message

Carlos Noguera

unread,
Jan 27, 2016, 11:05:18 AM1/27/16
to handlebars.java
Hi all,

I'm just starting with Handlebars, and I am struggling either with concepts or a bug (my money is of course on the former ;)

So, my question. Imagine something like:

class Dummy {
public String value;
public Collection<Dummy> subDummies;

public String getVal() {
return value;
}
public Collection<Dummy> getSubDum() {
return subDummies;
}}

@Test
public void testCache() throws IOException {
Dummy dummy1 = new Dummy(), dummy2 = new Dummy(), dummy3 = new Dummy(), dummy4 = new Dummy();
dummy1.value = "d1";
dummy2.value = "d2";
dummy3.value = "d3";
dummy4.value = "d4";

dummy1.subDummies = Arrays.asList(dummy3);
dummy2.subDummies = Arrays.asList(dummy4);


Collection<Dummy> dummies = Arrays.asList(dummy1, dummy2);
Handlebars handlebars = new Handlebars();
Template template = handlebars.compileInline("{{#this}}"
+ "{{val}}"
+ "{{#SubDum}}{{val}}{{/SubDum}}"
+ "{{/this}}");

I woud expect the template when applied to become

"d1d3d2d4"

what I'm getting instead is

"d1d2d2"

FYI i'm on handlebars v 4.0.3

Thanks.

Carlos

Dan McWeeney

unread,
Jan 27, 2016, 11:28:10 AM1/27/16
to handlebars.java
I think you want to use this:

{{this.val}}
{{#each subDum}}
{{this.val}}
{{/each}}

Looks your #this and #SubDum is getting ignored because those are block helpers that don't appear to be registered in your example, unless you have more code. I'm a bit suprised you aren't seeing a compile error but not looking at the code for handlebars.java right now.

--
You received this message because you are subscribed to the Google Groups "handlebars.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to handlebarsjav...@googlegroups.com.
To post to this group, send email to handleb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/handlebarsjava/41413809-8674-4901-869f-bb1a03d28dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carlos Noguera

unread,
Jan 27, 2016, 11:42:58 AM1/27/16
to handlebars.java
Thanks for the quick help,

On Wednesday, January 27, 2016 at 5:28:10 PM UTC+1, mcdan wrote:
> I think you want to use this:
>
>
> {{this.val}}
> {{#each subDum}}
> {{this.val}}
> {{/each}}

Sadly it still does not behave like I expected. With the same setup as before,

Template template = handlebars.compileInline("{{#this}}"
+ "{{this.val}}"
+ "{{#each SubDum}}{{this.val}}{{/each}}"
+ "{{/this}}");

gives
d1d2

instead of

d1d3d2d4



>
>
> Looks your #this and #SubDum is getting ignored because those are block helpers that don't appear to be registered in your example, unless you have more code. I'm a bit suprised you aren't seeing a compile error but not looking at the code for handlebars.java right now.

I think I don't get a compile error because #this and #subDum are actually mustache and not handlebars (see http://jknack.github.io/handlebars.java/gettingStarted.html when #each is presented)

Nevertheless, I have made some headway, I had a mistake on my original template (#SubDum instead of #subDum) however, having fixed that, I now get

d1d3d2

which is still not what I wanted, but at least it mimics the behavior I am seeing in my actual code (which is that the second iteration is skipped)

Any other ideas?

Carlos.

edgar

unread,
Jan 27, 2016, 12:22:31 PM1/27/16
to handlebars.java

Thanks for trying handlebars.java! and invite you to try my micro web framework to: http://jooby.org

This is a bug.. but you can get what you want by using explicit helpers:


{{#each this}}{{val}}{{#each subDum}}{{val}}{{/each}}{{/each}}



Can you file a ticket at github?

Thanks.
Reply all
Reply to author
Forward
0 new messages