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 (Actually I get that out of a database, but it's irrelevant to this discussion.)

domain {{ domain }}
nameserver {{ . }}

I want to generate a resolv.conf file on the fly using, say, PHP. Here is a short script that does just that.


    $template = file_get_contents('');
    $sys = array(
        'domain' => '',
        'ip'     => '',
        'ns'     => array( '', '' )
    $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


This is a trivial example, but it may whet your appetite for {{Mustache}}.

Flattr this
PHP and JavaScript :: 06 Jul 2011 :: e-mail


blog comments powered by Disqus