Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Last active March 9, 2016 02:26
Show Gist options
  • Save typeoneerror/2192941be3d6c346988d to your computer and use it in GitHub Desktop.
Save typeoneerror/2192941be3d6c346988d to your computer and use it in GitHub Desktop.
link-to-if component ala rails's link_to_if helper
import Ember from 'ember';
const {
Component,
computed
} = Ember;
const LinkToIfComponent = Component.extend({
condition: null,
routeName: computed('params.[]', function() {
return this.get('params')[0];
})
});
LinkToIfComponent.reopenClass({
positionalParams: 'params'
})
export default LinkToIfComponent;
{{#if condition}}
{{#link-to params=params}}
{{yield true}}
{{/link-to}}
{{else}}
{{yield false}}
{{/if}}
// assuming a route like "route/:foo_id/:bar_id"
{{#link-to-if "route" 1 2 condition=someBool as |linked|}}
Hello!
{{#unless linked}}
Locked!
{{/unless}}
{{/#link-to}}
// If `someBool` evals to truthy, renders:
// <a href="/route/1/2">Hello!</a>
// otherwise:
// Hello! Locked!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment