Is there an idiomatic way to generate a URL as a string in a Handlebars template?


Sometimes I want to generate and display a URL (to a specific route of my app) to the user, so that they can easily copy the URL to their clipboard. I have been using this.router.generate("routeName", dynamicSegmentObject) to generate the string, then exposing that as a property which my templates can display. Is there a better or more idiomatic way to do this?


That’s not something I’ve seen in 6 months working with Ember, and it’s not listed in the API, but it seems like a good candidate for a Handlebars helper. Unfortunately it requires access to this.router which is unavailable within helper definitions. You can get around that of course…

var router = App.__container__.lookup('router:main').router;


Cool. I thought it was odd that there isn’t a Handlebars equivalent of link-to that just generates the string instead of the full anchor tag. Good to know it’s not just me. I’ll probably use your container lookup approach to make my own helper for now.