-
Notifications
You must be signed in to change notification settings - Fork 7
02.0.0 Render Nested Resource
Patrick Baselier edited this page Oct 11, 2015
·
5 revisions
- User
{{render}}
to extract markup - Use nested resource
See the installation instructions. Use tag 2.0.0.
- Open
frontend/app/templates/products.hbs
. - Move
<div class='row carousel-holder'>...</div>
to a new filefrontend/app/templates/_carousel.hbs
and replace the markup with
{{partial 'carousel'}}
- Open
frontend/app/templates/products.hbs
. - Within the
<div class='products'>
container replace
<h4><a href='#'>{{product.title}}</a></h4>
with
<h4>{{#link-to 'products.show' product}}{{product.title}}{{/link-to}}</h4>
- Inspect the error shown in the Console tab in the browser. Ember is missing the
products.show
route, so let's create this. - In the terminal, enter
ember g route products/show
. - Open
frontend/app/router.js
and updateRouter.map
to
Router.map(function() {
this.resource('products', function() {
this.route('show', {
path: ':product_id'
});
});
});
- Open
frontend/app/templates/products.hbs
. - Move the markup wrapped by
<div class='content-detail'>
tofrontend/app/templates/products/show.hbs
(delete the content ofshow.hbs
) and replace it with{{outlet}}
:
<div class='content-detail'>
{{outlet}}
</div> <!-- /.content-detail -->
- Now the right column is updated every time you select another product. The content however, is still static HTML.
- Open
frontend/app/templates/products/show.hbs
and replace:-
<img class='img-responsive' src='http://lorempixel.com/800/300/technics/1/' alt=''>
with<img src={{model.image}}>
-
24.99
with{{model.price}}
-
Product Name
with{{model.title}}
-
See more snippets like this...
with{{model.description}}
-
- Navigating to
/products
shows an empty column on the right side. Ember uses theproducts/index
template to render if it can find one. - In the terminal, enter
ember g template products/index
. - Paste the code from this gist into
frontend/app/templates/products/index.hbs
.