You’re asking a good question — I definitely had the O_o face the first time I saw it too. There’s a few pieces to this — I’ll try to answer all of them the best I can.
The Syntax
The place you’ll typically see this ```hbs`Template```` stuff is in Component Integration tests. (Take a look at the guides to see what I’m talking about!)
The short about this syntax is: This is a way of writing templates inline with your javascript. This syntax will compile
The Layout Property
When you have a component with a template, there is some glue under-the-hood that connects them together.
Let’s say you have a component at the path app/components/my-component.js
. If you did not specify a layout property on that component, when it renders for the first time, it’s going to look for a template at the path app/templates/components/my-component.hbs
(Though, since the template is compiled to Javascript, it’ll technically be looking for app/templates/components/my-component.js
, but you’ll never make that file yourself — ember-cli handles that).
You can, if you want, specify your own layout in a component. Just import the template yourself!
// components/my-component.js
import Ember from 'ember';
import layout from 'my-app/templates/components/some-other-template';
export default Ember.Component.extend({
layout
});
In fact, addons have to do this because different Ember apps might resolve the location of the template differently so an add-on can’t know in advance how the template will be resolved (some apps might use pods, some might use a custom solution, who knows!).
Here’s an example of that from Ember Power Select: https://github.com/cibernox/ember-power-select/blob/master/addon/components/power-select.js#L3
The Babel Plugin
The other weird thing going on is this thing called Tagged Template Literals. This is one of the lesser-known ES6 features that allows you to extend the functionality of javascript string templates.
In Ember land, this is done through an add-on (you’ll see it in your package.json
!) called ember-cli-htmlbars-inline-precompile
. This more or less amounts to a Babel plugin which (I think) adds a little more functionality to what Tagged Templates would do alone.
Hope this helps!