0

Going through the tutorial, I've encountered this:

this.render(hbs`
    {{#list-filter filter=(action 'filterByCity') as |results|}}
      <ul>
      {{#each results as |item|}}
        <li class="city">
          {{item.city}}
        </li>
      {{/each}}
      </ul>
    {{/list-filter}}
  `);

I thought backticks represented a string? What is hbs then? Is it a function that is receiving handlbars snippet as an argument?

dsp_099
  • 5,801
  • 17
  • 72
  • 128

1 Answers1

3

I thought backticks represented a string?

No, backticks represent a template literal, the result of which is usually a string, but isn't necessarily. You get a string when the template literal isn't tagged, but this is a tagged template literal, which is when a template literal is passed into a function (hbs in this case); the result is whatever the function returns. It doesn't look like a function call, but it is.

More on MDN: Template lierals.

What is hbs then?

hbs is a function providing handlebars handling for the template, see this question and its answers.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875