Skip to content

Lets discuss templating... #116

@ivan-kleshnin

Description

@ivan-kleshnin

AmpersandJS declares itself to be template agnostic. But it turns out not to be exactly true.
I tried my best to combine popular (and well written) Nunjucks template engine with Ampersand views and come to frustrating conclusions.

  1. Most template engines want to operate on native JS data. Arrays, Objects you know. Ampersand works with wrapped data. There mismatch begins. I tried to convert data with toJSON() but it seems to target mostly backend stuff as it misses derived and session by default. Override or add some method? I wanted to be conventional, not reinvent a wheel right from the start. But passing Ampersand objects fails completely. Nunjucks, for example, can't even iterate Ampersand collection with its {% for ... in %} loop construction. And custom JS code is forbidden or hard to implement. I wonder why I should reimplement loops, are we solving puzzles instead of work? Logic-less templaters fail by the same reason. Embedded JS template engines could help but there are none decent at this moment. Don't advice me EJS, please :) So all this agnostic declarations look more like advertisements after all.

It perfectly shows, but the way, how much flawed is OOP. But I still think that docs or "Human JavaScript" book had to mention this ubiquitous issue.

  1. Major part of Ampersand documentation and code propagates view bindings. But that bindings are an alternative template solution on their own, aren't they? They require pure HTML and call it "template". How confusing! To implement loop then I should fall back to helper. To implement if... I don't even know... I suppose that template engines and Ampersand view bindings are mutually exclusive. At least in some sense. And documentation is silent about this again.

Most of this are not exactly Ampersand issues. My point on this is that documentation should provide guidance, should show real world examples and pitfalls. If you guys use that view bindings heavily and they prove themselves – let us know. Agnostic mottos just for a sake of it are useless, we all know that being agnostic is good but bitter truth is better. If not – why bother?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions