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?

4
  • hbs is handlebars. See the first answer in the dupe. Commented Dec 31, 2016 at 11:34
  • @PraveenKumar I figured. How come the backticks don't error out though, syntax-wise? Commented Dec 31, 2016 at 11:36
  • Coz, that's a valid syntax boss. Commented Dec 31, 2016 at 11:38
  • 1
    @PraveenKumar: Since the question you linked and its answers don't address the template literal, it's not a duplicate. But it's strongly related. Commented Dec 31, 2016 at 11:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.