Hi,
I was wondering, what is the idiomatic way of selecting a partial template based on the model type?
Suppose we have a class hierarchy:
public class Pet {
private String name;
private String owner;
public Pet(String name, String owner) {
this.name = name;
this.owner = owner;
}
public String getName() { return
this.name; }
public String getOwner() { return this.owner; }
}
public class Dog extends Pet {
public Dog(String name, String, owner) { super(name, owner); }
}
public class Cat extends Pet {
public Cat(String name, String, owner) { super(name, owner); }
}
, a model:
Pet[] model = {
new Cat("Mittens", "Pat"),
new Dog("Rocky", "Sue")
};
and partials:
Dog.hbs:
{{ name }} is {{ owner }}'s best friend.
Cat.hbs:
{{ name }} is indifferent about {{ owner }}.
Now, how do I write the template for Pet[]?
I guess I could add "isCat", "isDog" properties to the subtypes and include appropriate partials conditionally:
{{#each}}
{{#if isDog}}{{> Dog}}{{/if}}
{{#if isCat}}{{> Cat}}{{/if}}
{{/each}}
but this feels like a hack and doesn't scale at all. Did I miss something in the documentation or is such usecase not supported?
Regards,
Jakub