Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember yield param passing

I'm trying to pass an argument to a yield block, however I missing something that I don't see. Here is the case:

components/table-notes.hbs

<table>
   ...
  <tbody>
    {{#each note in notes}}
      <tr>
        <td>{{yield note}}</td>
        ...
      </tr>
    {{/each}}
   </tbody>
 </table>

elsewhere

{{#table-notes notes=model.notes}}
  //do something with each note
{{/table-notes}}

Is it anything wrong or incomplete with this param passing?

Thanks in advance.

like image 894
tehAnswer Avatar asked Jan 08 '23 18:01

tehAnswer


1 Answers

I don't think you can do this in a version prior to 1.10. In 1.10 though, you can do the following:

Declare the component template and yield

<script type="text/x-handlebars" id="components/table-notes">
   {{#each notes as |note|}}
    {{ yield note }}
   {{/each}}
</script>

And also declare in the template using the component that the variable is called note as follows:

<script type="text/x-handlebars" data-template-name="index">    
  {{#table-notes notes=model.notes as |note|}}
    <h3>{{ note }}</h3>
  {{/table-notes}}
</script>

Working example here

You can read more about block params in components, a new feature in 1.10, here.

like image 143
Kalman Avatar answered Feb 28 '23 06:02

Kalman