How do I do polymorphism in a loop with StringTemplate?

82 Views Asked by At

Let's say my model has an array of class IAnimal which I want to render using a template.

Each implementation of IAnimal has its own template (.st file) and this list is rendered within another generic template.

generic(e)::= <<
    List of animals : 
    $e.Animals:{ a | $renderAnimal(a)$} 
>>

I understand that I can use an import statement to override renderAnimal but then it will use this override for all the animals, no matter their type.

I could not find an example in the documentation about inheritance

How can I make my generic template use a different template for each item of e.Animals depending on its type ?

0

There are 0 best solutions below