Skip to content

Instantly share code, notes, and snippets.

@teaplanet
Created December 30, 2014 16:26
Show Gist options
  • Save teaplanet/dc198f039a7005f6cffd to your computer and use it in GitHub Desktop.
Save teaplanet/dc198f039a7005f6cffd to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 5-1
<!-- http://learn.ractivejs.org/conditional-sections/1 -->
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<div id='container'></div>
<script id='template' type='text/ractive'>
{{#if signedIn}}
<!-- message for signed-in users -->
<p>Welcome back, {{username}}!</p>
{{/if}}
{{#if notSignedIn}}
<!-- message for non-signed-in users -->
<p>hi there! Please <a class='button' on-click='signIn'>sign in</a></p>
{{/if}}
</script>
var ractive = new Ractive({
el: 'container',
template: '#template',
data: {
signedIn: false,
notSignedIn: true
}
});
ractive.on('signIn', function(){
var name = prompt('Enter your username to sign in', 'ractive_fan');
ractive.set({
username: name,
signedIn: true,
notSignedIn: false
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment