DOMtempl

HTML templating that brings you peace

Enter the temple

Extra, Extra, This Just In!

DOMtempl can now help you achieve whitespace nirvana. Whether you're an XML pedant or a indent hater, it will accommodate your whitespace styling automagically and will replicate it faithfully. I'm 99% sure no string-based templating engine is even remotely capable of such behavior. The hack is very elegant and is only possible with DOM templating.

Python and Node.js ports available

That's right. Check out the documentation section.

Ruby port available

Why not ruby? Also check out datagnan - a rather similar, yet different ruby dom-templating library. (We're about 70% compatible).

The pitch

Imagine your template looking like this:


<ul>
    <li data-each="menu">
        <a href="index.html" data-attr-href="url" data-var="title">Click me</a>
    </li>
</ul>

After reading the variable names in the data-* commands, and the default values contained within the nodes, DOMtempl will obtain the following data map:


{
    "menu": [
        {
            "url": "index.html",
            "title": "Click me"
        }
    ]
}

Now, you can keep those values, discard them, or overwrite them partially or fully. Let's say you decided on the following:


{
    "menu": [
        {
            "title": "Click me",
            "url": "index.html",
        },
        {
            "title": "No, click me!",
            "url": "other.html",
        }
    ]
}

Out of that new data, DOMtempl can now create new HTML:


<ul>
    <li>
        <a href="index.html">Click me</a>
    </li>
    <li>
        <a href="other.html">No, click me!</a>
    </li>
</ul>

Take a look at some template samples, and code snippets in the documentation section.

Download

Git repository:

git clone https://github.com/makesite/domtempl.git

Or grab a snapshot of the latest version.

See also

Still undecided? Read more about original reasoning and the (mis)features!

License

Two-clause BSD.