Skip to content

Instantly share code, notes, and snippets.

@teaplanet
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save teaplanet/c6d5c772db0ce36c1b58 to your computer and use it in GitHub Desktop.

Select an option

Save teaplanet/c6d5c772db0ce36c1b58 to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 3-2
<!-- http://learn.ractivejs.org/expressions/2 -->
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<div id='container'></div>
<script id='template' type='text/ractive'>
<table>
<tr>
<th>Price per {{item}}</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<tr>
<td>{{ format(price) }}</td>
<td>{{ quantity }}</td>
<td>{{ format(price * quantity) }}</td>
</tr>
</table>
</script>
var ractive = new Ractive({
el: 'container',
template: '#template',
data: {
item: 'pint of milk',
price: 0.49,
quantity: 5,
format: function(num) {
if (num < 1) {
return (100 * num) + 'p';
}
return '£' + num.toFixed(2);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment