Skip to content

Instantly share code, notes, and snippets.

@hjumeau
Last active March 1, 2016 20:07
Show Gist options
  • Save hjumeau/cd20685ea026b51473f5 to your computer and use it in GitHub Desktop.
Save hjumeau/cd20685ea026b51473f5 to your computer and use it in GitHub Desktop.
Conditionals
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember 2.0'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default Ember.Route.extend({
model(){
return {
isFast: true,
isFueled: true,
person: {
firstName:'Yehuda',
lastName: 'Katz'
},
isAtWork: false,
isReading: true,
hasPaid: false,
total: 120
};
}
});
<div>
{{if model.isFast "zoooom" "putt-putt-putt"}}
</div>
<div class="is-car {{if model.isFast "red" "blue"}}">
</div>
<div>
{{input type='text' class=(if model.isFueled "zoooom")}}
</div>
{{#if model.person}}
Welcome back, <b>{{model.person.firstName}} {{model.person.lastName}}</b>!
{{else}}
Please log in.
{{/if}}
{{#if model.isAtWork}}
Ship that code!
{{else if model.isReading}}
<div>You can finish War and Peace eventually...</div>
{{/if}}
{{#unless model.hasPaid}}
<div>You owe: $ {{model.total}}</div>
{{/unless}}
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.red {
background-color: red;
height:20px;
}
.blue {
background-color: blue;
height:20px;
}
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.2.0",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "2.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment