ruidlopes / minimal.js

minimal.js: HTML+JSON template engine
172 stars 13 forks source link

ETA & Discussion RE: Template composition (includes, partials, etc.); #9

Open chrisjacob opened 13 years ago

chrisjacob commented 13 years ago

I noticed in the Coming Soon "Template composition (includes, partials, etc.);" ... I'm very interested to hear your idea's for this feature - and any info on when a solution may be released.

ruidlopes commented 13 years ago

Ok, here's the gist of it. The issue of implementing template composition is that it requires some kind of external interaction:

1) Server-side rendering: the included templates must be loaded from disk; 2) Client-side rendering: the included templates must be loaded via AJAX.

Once again, I wonder if this feature should be present at minimal.js level, or if it should be a feature provided on top of it. Honestly, I don't have a final answer on this.

Ideas?

chrisjacob commented 13 years ago

Very difficult problem to solve now that JS templates need to consider serverside + clientside (as they should).

Right now it's out of my scope of knowledge - but if I have any ideas, or see any other systems managing this issue well I will post it here ^_^

Right now I'm more in the bandwagon of static file generation like Nanoc or LESS before deployment. I suppose that could mean running node.js locally, with jsdom, processing the $m calls and spitting out the final source into another file... not sure how that scales tho. And you're right - not sure if this is a problem that minimal.js should solve in core.

ruidlopes commented 13 years ago

Indeed. I'll leave the ticket open, such that someone else might find a simpler way to do it (or if I get around and implement something).

lafncow commented 12 years ago

I would love to see this feature & not certain of the best implementation, but just wanted to put this out there: to stay in the "minimal" style, you could also use iframes in the template that would point to the included files. When the iframe is tagged as an include, minimal.js could then clone its content, remove the iframe, insert the content in the parent doc as a partial, then render the whole document as usual. Side-effects:

...so off the top of my head I could see this:

template.html: `

` myInclude.html: `````` ``` ...with ```$m({ul:[{b:'foo'},{b:'bar'}]});``` rendering as: `````` Make sense? Please disagree at will, I'm new to minimal and excited about the possibilities. ``````