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.

Bottom line: I think the declarative approach will be the most used when you need to define templates, but remember: if you want, you can do everything from JavaScript.


~ by Luis Abreu on October 19, 2009.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: