Skip to content

Instantly share code, notes, and snippets.

@GendelfLugansk
Last active January 20, 2018 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GendelfLugansk/add9fc188e2095c53f4d3fb1bb3f2bce to your computer and use it in GitHub Desktop.
Save GendelfLugansk/add9fc188e2095c53f4d3fb1bb3f2bce to your computer and use it in GitHub Desktop.
Yield demo
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ["person-card"]
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ["person-card"]
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export function isEqual(params/*, hash*/) {
return params[0] === params[1];
}
export default Ember.Helper.helper(isEqual);
<h1>Yield demo</h1>
<small>First component yields a simple js object. Second component yields a string.
Is-equal is a simple helper which compares two values.</small>
<h2>Component 1</h2>
{{#person-component as |section|}}
{{#if section.isTitle}}Person Card{{/if}}
{{#if section.isName}}Name: Jon Snow{{/if}}
{{#if section.isOccupation}}Occupation: bastard, King of the North{{/if}}
{{/person-component}}
<h2>Component 2</h2>
{{#person-component-2 as |section|}}
{{#if (is-equal section "title")}}Person Card{{/if}}
{{#if (is-equal section "name")}}Name: Cersei Lannister{{/if}}
{{#if (is-equal section "occupation")}}Occupation: Cersei of the House Lannister, the First of Her Name, Queen of the Andals and the First Men, Protector of the Seven Kingdoms{{/if}}
{{/person-component-2}}
<h3>{{yield "title"}}</h3>
<div class="person-data">
<h4 class="name">{{yield "name"}}</h4>
<div class="occupation">{{yield "occupation"}}</div>
</div>
<h3>{{yield (hash isTitle=true)}}</h3>
<div class="person-data">
<h4 class="name">{{yield (hash isName=true)}}</h4>
<div class="occupation">{{yield (hash isOccupation=true)}}</div>
</div>
{
"version": "0.13.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment