Skip to content

Instantly share code, notes, and snippets.

@mydea
Created May 31, 2016 15:54
Show Gist options
  • Save mydea/87744021687e08758bca06626fe48db1 to your computer and use it in GitHub Desktop.
Save mydea/87744021687e08758bca06626fe48db1 to your computer and use it in GitHub Desktop.
url-for helper
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export function t(params/*, hash*/) {
return params[0];
}
export default Ember.Helper.helper(t);
import Ember from 'ember';
export default Ember.Helper.extend({
routing: Ember.inject.service('-routing'),
compute([routeName, model]) {
let router = this.get('routing.router');
if (model) {
return router.generate(routeName, model);
} else {
return router.generate(routeName);
}
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none'
});
Router.map(function() {
this.route('details', { path: 'details/:id' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
});
<h1>Welcome to {{appName}}</h1>
{{t (url-for 'index')}}<br>
{{t (url-for 'details' 1)}}<br>
{{t (url-for 'details' 2)}}<br>
{
"version": "0.8.1",
"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.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment