How are client-side templates and routes integrated with Ember?


(Will Macaluso) #1

I’m trying to understand Discourse in the context of a Ember app. (Disclosure: I’m an Ember noob with an Angular background). I think the Rails end is pretty straightforward to understand.

I’ve been looking at this post which is super helpful for extending discourse, but it’s difficult to see how some of the inner workings relate.

I’ve decided to try understanding the client-side arch/pipeline using the “about” resource (i.e. 301 Moved Permanently), since it’s relatively simple. From what I understand here are the important files:

  • Routing: about.js.es6 and application_routes.js in app/assets/javascripts/discourse/routes
  • Template: about.hbs in app/assets/javascripts/discourse/templates

How does Discourse connect the about.hbs handlebars template to Ember? How is this route connected to Ember? I couldn’t find Discourse.AboutRoute in the code, but found it in chrome devtools, so I imagine it’s dynamically loaded.

On an unrelated note, I really like Discourse and how open the community is.


Where to modify Signup call-to-action content text
(Robin Ward) #2

What you’re seeing is convention over configuration!

If you declare a route in your ember app’s router, say: this.resource('cool', { path: '/cool'});

Then if you try to load /cool in your browser, ember will look for a few things. If they’re defined by your application ember will wire them up. If they’re not defined it will use the default implementaiton.

So let’s say I added cool.hbs. If I then navigated to that route it would just show that template. If I wanted special logic, say to load something via AJAX before showign the template, I could define CoolRoute in the file routes/cool.js.es6 and ember would use that when navigating to the template. If there’s a model hook it would execute that before putting you in there.

The official docs are a good place for more on this!


(Will Macaluso) #3

Thanks for your reply - I think a tiny insecure voice deep inside of me was crying “Where is the config file that maps all of these things to each other!”, but as long as I know the convention I shouldn’t need to know the underlying details :smile: