flatiron / plates

Light-weight, logic-less, DSL-free, templates for all javascript environments!
MIT License
831 stars 69 forks source link

Example project with template nesting #121

Open adam-lynch opened 9 years ago

adam-lynch commented 9 years ago

I like the idea of plates but I'm not sure how it would work in a project with a lot of partial templates that have to include other templates. Note: I'd be thinking of using it on its own, not as part of flatiron.

Let's say there's a template which has an element which contains another partial template which includes more, etc. Imagine there are a lot of top-level templates like this. How would someone manage this and the mappings needed? Each top-level template would need a specific permutation of mappings & partial injections applied to it. Or in other words, each partial would need its own mapping but this would be have to be managed somehow.

Also, each template may of course use different names for vars. So if one template includes another, the first mapping needs to converted into the second.


With a DSL (let's say with swig), you kind of get this for free; for example:

a.swig.html

<div>
<p>{{ hello }}</p>
{% include './b.swig.html' with { world: hello } only %}
</div>

b.swig.html

<p>{{ world }}</p>

And then rendering a.swig.html with {hello: 'a'} will give :

<div>
<p>a</p>
<p>a</p>
</div>

Are there any example projects out there that would show how this should be done?

serapath commented 9 years ago

I am also interested in this. Plates exports a method "partial" and "append" which are equivalent and which do sub templates. Still, i'm sometimes confused what would be the best way to nest stuff, because there seem to be several ways, one which seems to not need "partial" and "append" at all, but i'm not sure. :-)

I'm planning of using "plates" in my own templating language which should support data binding on top.