Last active
August 29, 2015 14:12
-
-
Save teaplanet/e7c452ad646913dbc842 to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 5-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- http://learn.ractivejs.org/conditional-sections/2 --> | |
<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> | |
{{else}} | |
<!-- message for non-signed-in users --> | |
<p>hi there! Please <a class='button' on-click='signIn'>sign in</a></p> | |
{{/if}} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ractive = new Ractive({ | |
el: 'container', | |
template: '#template', | |
data: { | |
signedIn: false | |
} | |
}); | |
ractive.on('signIn', function(){ | |
var name = prompt('Enter your username to sign in', 'ractive_fan'); | |
ractive.set({ | |
username: name, | |
signedIn: true | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment