After <script type="text/x-handlebars"
a. I'm wondering in what cases do I put data-template-name
and what cases do I put id
.
In the guide tutorial video source they use id
s exclusively.
In the todomvc source and pretty much everywhere else I've seen, data-template-name
is used.
b. And what exactly is put after data-template-name
and id
(i.e. what comes after their =
)?
a) AFAIK id
is the newer version of data-template-name
, and they seem to work the same.
b) The id
allows you to identify a template it in your routing, rendering or 'views'.
For Routing:
You can use this name to help the router identify which template to render, e.g. use this.render('displayStuff)
during the renderTemplate
in a route, to "override" the default template that belongs to the route.
See also: http://emberjs.com/guides/routing/rendering-a-template/
For Rendering:
Templates allow specific ways to change rendering. Ember-Handlebars provides {{render}}
and {{partial}}
to change the default template associated to the view.
See also: http://emberjs.com/guides/templates/rendering-with-helpers/
For Views:
By default, a view will find its corresponding template based on convention. So the somethingView
has an associated somethingController
and a something
template (so template with id='something'
). A view will also allow to forgo this convention by setting its templateName
parameter.
See also: http://emberjs.com/guides/views/inserting-views-in-templates/
hope it helps!
Both work and are correct but data-template-name has a higher precedence and gives you more freedom re: element id's (they wont conflict with template ids)
via http://discuss.emberjs.com/t/ember-components-id-or-data-template-name-in-handlebars-script-tag/3847
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With