Quickly render mustache templates
Call dc
with a template -t
and some data -d
. Both the template and the data arguments can be one of the following forms:
- File
-t example.html.mustache
-d data.json
- URL:
-t 'http://example.com/example.html.mustache'
-d 'http://jsonip.com'
- String:
-t '<p>{{foo}}</p>'
-d '{"foo": "bar"}'
$ ./dc -t '<div>{{#dicks}}<p>{{.}}</p>{{/dicks}}</div>' -d 'http://dicks-api.herokuapp.com/dicks/5'
$ ./dc -t template.html.mustache -d products.json
A useful feature of dc
is the built in web server. Using the -s
option dc
will start a web server listening on http://localhost:8080
and opens up a browser window with your rendered creative. From here on out you can freely refresh the page and the template will be re-rendered.
$ ./dc -s -t template.html.mustache -d products.json
Access with recommender data.
$ cat template.html.mustache
<ul>
{{#products}}
<li>
<a href="{{deeplink}}">{{from_airport}}-{{to_airport}}</a>
</li>
{{/products}}
</ul>
$ cat products.json
{
"products": [
{
"from_airport": "TRN"
"to_airport": "PMO",
"deeplink": "/Search.aspx?culture=it-IT&from=TRN&to=PMO&departuredate=2014-08-20&returndate=2014-08-22",
}
]
}
$ dc -t template.html.mustache -d products.json
<ul>
<li>
<a href="/Search.aspx?culture=it-IT&bookingtype=flight&from=TRN&to=PMO&triptype=roundtrip&departuredate=2014-08-20&returndate=2014-08-22&adults=1&children=0&infants=0&showNewSearch=false&utm_campaign=retargeting">TRN-PMO</a>
</li>
</ul>
You can read the documentation on mustache logic-less templating here or play around with their demo.