Mustache is on heavy rotation here at the moment, and I’m using it with a variety of languages. I’ve mentioned Mustache before, in the context of CouchDB, for example.
Mustache is quite powerful as a “logic-less templating system for HTML, config files, anything”. Let me show you a bit of how I’m using it at the moment.
Suppose I have a template in a file called template.in
. (Actually I get that
out of a database, but it’s irrelevant to this discussion.)
domain {{ domain }}
{{#ns}}
nameserver {{ . }}
{{/ns}}
I want to generate a resolv.conf file on the fly using, say, PHP. Here is a short script that does just that.
<?php
require_once('Mustache.php');
$template = file_get_contents('template.in');
$sys = array(
'domain' => 'mens.de',
'ip' => '127.0.0.4',
'ns' => array( '1.1.1.1', '2.2.2.2' )
);
$m = new Mustache;
echo $m->render($template, $sys);
?>
After retrieving the content of the template and populating the $sys
array, I
can have Mustache apply the values in the array to the template, and the
outcome is
domain mens.de
nameserver 1.1.1.1
nameserver 2.2.2.2
This is a trivial example, but it may whet your appetite for {{Mustache}}.