minimal.js icon indicating copy to clipboard operation
minimal.js copied to clipboard

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

Open chrisjacob opened this issue 13 years ago • 4 comments

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.

chrisjacob avatar Apr 05 '11 15:04 chrisjacob

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?

ruidlopes avatar Apr 05 '11 16:04 ruidlopes

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.

chrisjacob avatar Apr 05 '11 23:04 chrisjacob

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).

ruidlopes avatar Apr 06 '11 07:04 ruidlopes

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:

  • node.js would have to fetch the content itself
  • on the client side minimal would have to wait for all relevant iframes to load before rendering
  • same-origin policy would be in effect on the client side (minimal would have to watch out for that)

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

template.html: `

  • $myInclude
`

myInclude.html:

`````` ```

...with $m({ul:[{b:'foo'},{b:'bar'}]});

rendering as:

    <li><b>foo</b></li>
    <li><b>bar</b></li>
</ul>```

Make sense? Please disagree at will, I'm new to minimal and excited about the possibilities.

lafncow avatar Dec 15 '11 18:12 lafncow