Created
December 30, 2014 16:26
-
-
Save teaplanet/dc198f039a7005f6cffd to your computer and use it in GitHub Desktop.
Ractive.js Tutorial 5-1
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/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> |
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, | |
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