Skip to content

Instantly share code, notes, and snippets.

@teaplanet
Created December 23, 2014 11:25
Show Gist options
  • Select an option

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

Select an option

Save teaplanet/41bf0c041e786a0ed17e to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 2-2
<!-- http://learn.ractivejs.org/nested-properties/2 -->
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<div id='container'></div>
<script id='template' type='text/ractive'>
<h2>Country profile</h2>
{{#with country}}
<p>{{name}} is a {{climate.temperature}} country with {{climate.rainfall}} rainfall and a population of {{population}}.</p>
{{#with capital}}
<p>The capital city is {{name}} (<a href='https://maps.google.co.uk/maps/place/{{name}}/@{{lat}},{{lon}},12z' target='_blank'>see map</a>).</p>
{{/with}}
{{/with}}
{{#country}}
'#' instead of 'with'.
{{/country}}
</script>
var ractive = new Ractive({
el: 'container',
template: '#template',
data: {
country: {
name: 'The UK',
climate: { temperature: 'cold', rainfall: 'excessive' },
population: 63230000,
capital: { name: 'London', lat: 51.5171, lon: -0.1062 }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment