Customizing tagName/attributes of top-level template


#1

Hello,

I’m migrating an Ember app to 2.7, and hence need to get rid of uses of Ember.View. I have a bunch of places in the app where I use the Route’s render method to render some template into an outlet. The rendered template typically also have a view associated with it, which is where I customize it’s tagName, class, etc.

Now, if I can’t use Views any more, what are my options?

  1. If I try to introduce a component, i.e just using my template to render some other component - then I get a wrapper ‘div’ which I can’t control, right?
  2. I tried to just change my view.js file to be a component class instead of view… as far as I can tell - it works. But it really doesn’t feel right…

So what is the correct way of doing this now?

In other words, how do I customize a template’s wrapper tag without views?


#2

A barebones template (one that belongs to a route) doesn’t have any tag. If you want to customize a component’s tag name you can do so by passing or setting the tagName property. If you set it to an empty String, the component will render just the content of the template (“tagless component”).

See also: https://guides.emberjs.com/release/components/customizing-a-components-element/


#3

ohhh. I don’t know why I thought a bare-bone template have a wrapper tag. Thanks!