...

/

Expressions in Templates

Expressions in Templates

In this lesson, you’ll learn to use expressions in templates of an Ember application.

At this point, we have several slightly differing dynamic expressions in our templates, so let’s stop for a moment to explore them.

Let’s first take a look at the songs.hbs template and go from top to bottom:

Press + to interact
{{!-- app/templates/bands/band/songs.hbs --}}
{{page-title "Songs | Rock & Roll with Octane" replace=true}}
{{#if @model.length}}
<ul>
{{#each @model as |song|}}
<li class="mb-2">
{{song.title}}
<span class="float-right">
<StarRating
@rating={{song.rating}}
@onUpdate={{set song "rating"}}
/>
</span>
</li>
{{/each}}
</ul>
{{else}}
<p class="text-center">
The band has no songs yet.
</p>
{{/if}}

#if and #each are basic Ember helpers. You’ll see helpers in more detail and make your own in the Helpers chapter.

@model denotes an argument that was passed into this context and is immutable. This is also known as a named argument. In this case, it’s the model returned from the ...

Access this course and 1400+ top-rated courses and projects.