Declarative vs imperative approach: which to choose?
Now that we’ve seen how to use two approaches (declarative vs imperative) for defining templates, you might be asking yourself which one you should pick. As always, I’d say that there is no definitive answer here. Having the option for both is great and means that templates can get used by everyone.
Having said this, I must say that I find it appropriate to base my templates on a declarative approach. Nobody can deny that it’s just “too easy” to build templates declaratively and I’ll be using them whenever I require templates. However, there still might be some reason which forces you from adding the declarative markup needed for template definition to the HTML of the page.
In those cases, the easiest strategy is to create a dumb node and use the itemRendering for generating the correct HTML. As we’ve seen, template contexts make it easy to get back the data used for instantiating the template and that should be enough for all the scenarios you might face.