ability to avoid creating the dummy parent div which has the class "ember-view"
Why ember enforces creating a parent div for any created components or view ?
actually, you can avoid the "creation of a parent div" if you set the tagName property on your Component/View manually. So, if you want to have an unordered list view, you'll do something like
var MyListView = Ember.View.extend({
tagName: 'ul'
});
and in your handlebars you're just adding <li></li> elements.
<li>
I'am so
</li>
<li>
unorderded
</li>
@herom thanks for you quick response.
But what if i want to avoid creating parent tag at all, i want to depend on my handlebars only ?
I don't think that this is possible as the view would not know its boundaries (which is clear if you see the view as a representation of an actual DOM element). What's the particular use case you're trying to cover? Could you perhaps provide a jsbin?
My use case is; I am trying to create a component and found that ember added a parent div which wrapping my component html and this broke my css .
`
Hi there
The solution i did to define a javascript component class and override the tagName and remove the top level tag from the handlebars to the required output to be like this
` Hi there
This pattern happens with me many times. and this is a working solution but I am not sure if this the best practice or not. I am wondering if we have a better solution instead of creating the javascript component or have the option to avoid creating this parent div and take my handlebars without adding the parent div.
I don't think that there is some "better" practice to achieve this, as views and components are also targets for actions, etc. so how would Ember detect if the code is related to a Component/View or is just "some random DOM markup" and distinguish between this possibilities? You need to tell Ember what's this.$() and therefore which is its DOM representation (at least that's what I know so far).
As I remember in backbonejs you can specify the element that the view responsible for via a normal jquery selector otherwise a new element will be created.
anyway this works for now and hope if they can improve this in the future or not.
thanks a lot man.
No problem - you're welcome :+1: :smiley:
TagName null
@stefanpenner If use tagName: null the HTML defaults to the normal div tag. If I use tagName: 'null' instead I get
@stefanpenner and @notmessenger I have just tried it. When using tagName: null you tell ember to create div which is the default value.
and If you use tagName: 'null' it will create a tag <null > </null>
But if you want to avoid creating the tag at all you can keep it empty like tagName: '' and this worked perfectly with me. and @herom btw this is the solution for my problem above.
cool thing, didn't know about that @abousamra - thanks for update and sharing :+1:
The tagName: '' technique doesn't appear to be documented or under test, and from what I can tell when used internally is always coupled with 'isVirtual: true.' I'd consider it a private API, personally, however useful.
@endash good point and should be considered, thanks.
@endash correct
and If you use tagName: 'null' it will create a tag
oops, answered from my phone '' as endash pointed out is correct, and likely coupled with isVirtual (if that is what you need.
Although isVirtual may not be what you want, it depends on the use-case
Man I used to be such a cowboy developer. Now I go, "Not documented? Not tested? I have no idea what this is actually doing today, or what it might do tomorrow. PASS!"
FWIW this technique at least in 1.7.0 will potentially seriously b0rk the children of a collectionview
tagName: "", fixed it for me