Helma Logo
main list history

JS-based implementation of snippets (aka subskins)

Just for a simple test implementation I've created two files as attached to this wiki page.

nametypesize
rendersnippet.jsundefined bytes
html.snippetsundefined bytes

renderSnippet takes two arguments just as renderSkin does: the first defines the snippet, the second the usual param object.

The snippet argument is composed of the file name (without the extension -- which is .snippets, btw.) and the snippet's name. Both values are separated by a colon.

Here's an example call:

renderSnippet("html:image", {src: "http://dev.helma.org/static/xmlbutton.gif"});

This would (or should) render the "image" snippet which is contained in the file Global/html.snippets (currently only global snippets are supported).

A snippets file contains HTML markup with Helma macros as we know it. But furthermore, a special tag (which is an HTML comment in disguise) marks the beginning of a snippet:

<!snippet:image>

The name is composed of the <!snippet: prefix followed by the snippet's name and it ends with a closing > at last.

Each snippet ends right before the next one begins -- or at the end of the file, resp.

Well, it's all done very quickly and without a lot of error testing or checking, but IMHO it proves the point of subskins pretty well. // tobi