0

I'm trying to understand EmberJS template convention in Discourse. Here's a snippet from app/assets/javascripts/discourse/templates/discovery/categories.hbs

{{#discovery-categories refresh="refresh"}}
  {{component controller.categoryPageStyle
              categories=model.categories
              latestTopicOnly=controller.latestTopicOnly
              topics=model.topics}}
  {{!-- my-template --}}
{{/discovery-categories}}

What is the meaning of discovery-categories and component? For example I want to insert my-template to extend categories.hbs, what is the convention I should use to create file with my template?

megas
  • 21,401
  • 12
  • 79
  • 130

1 Answers1

1
  1. discovery-categories is the name of the component which is called statically using the name of the component.

  2. Whereas in the second line 'component' is a template helper which loads the component dynamically using the name specified via property controller.categoryPageStyle.

3.my-template is the yield block , where you can have context of the component discovery-categories if its yield. for eg. if discovery-categories has a property foo you can write something like

{{#discovery-categories refresh="refresh" foo="Some Text"}}
  {{component controller.categoryPageStyle
              categories=model.categories
              latestTopicOnly=controller.latestTopicOnly
              topics=model.topics}}
  {{foo}}
{{/discovery-categories}}
  • 1
    I cant find `discovery-categories` component in [discours](http://www.discourse.org/) src code ?. – Ember Freak Oct 24 '16 at 16:50
  • 1
    Their current source code as of i write is in this file https://discourse-cdn.global.ssl.fastly.net/try/assets/application-38979d6a8c030cb6fbab15d279375c5dbf5a90988362baa408337c1cb0ee5cc3.js if you search for `discovery-categories` you can see it , its defined like this `define("discourse/components/discovery-categories"` since its a compiled code we cant make out exactly what it does. – Mohamed Jahaber Sadiq Oct 25 '16 at 07:40