Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion about "data-template-name" and "id" in "<script>" tag

Tags:

ember.js

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 ids 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 =)?

like image 758
HaoQi Li Avatar asked May 28 '13 08:05

HaoQi Li


2 Answers

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!

like image 80
harn145 Avatar answered Oct 05 '22 08:10

harn145


  • 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

  • also when you move your handlebars templates to stand alone files (production situation lets say) you won't need to worry about id vs data-template-name (let your build tools do this for you based on the template file name)
like image 41
Craicerjack Avatar answered Oct 05 '22 07:10

Craicerjack