Quantcast
Channel: Comments on: using javascript templates
Viewing all articles
Browse latest Browse all 12

By: Enrique Amodeo

$
0
0

Good post, specially the part about self contained widgets.

I’ve been reading the comments and I think the topic about transforming your data so that it can be used to hydrate a logic less template is very important.

Some people want logic full template because they want to embed that kind of transformation logic into the template, but that violates the SoC. Templates should be used to render HTML (or CSS…) but not to transform data too, they are completely unrelated concerns. That’s why I prefer logic less templates.

It is usually the case you need two different models. A model to use for business logic and another one for template rendering. The transformation between both can be done either in a method of the former, or in an adapter/wrapper for the template. This transformation can take care of formatting issues (currency, dates) and even structural changes. The formatting logic usually have internationalization issues, so it’s not so simple as may appear at first look. Of course if both data structures are exactly the same, and no special formatting is needed, this intermediate transformation layer is not needed. This way we avoid violating SoC and have a more testable system.


Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles





Latest Images