# Render a component outside of the template in EmberJS

**URL:** https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626
**Category:** Uncategorized
**Created:** [May 6, 2016, 9:39pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626 "2016-05-06T21:39:52Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Charles\_Bourasseau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/charles_bourasseau/32/11568_2.png) [@Charles\_Bourasseau](https://discuss.emberjs.com/u/Charles_Bourasseau)
#### Post date: [May 6, 2016, 9:39pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/1 "2016-05-06T21:39:52Z")

</div>

I want to render a modal which is defined inside a template but this modal should be insert into the DOM outside of the template.

e.g.

my-list.hbs:

```
 <div>
    <button>Create item</button>
    {{#if creatingItem}}
      {{item-creation-modal}}
    {{/if}}
    <ul>
      {{#each items as |item|}}
        <li>{{item.name}}</li>
      {{/each}}
    </ul>
  </div>

```

Basically what I want is to be able to render `{{item-creation-modal}}` outside of the DOM (typically at the end of the DOM) to be sure it’s above everything.

How can I achieve this?

---

<div class="post-metadata">

### Author: ![babblesort](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/babblesort/32/10988_2.png) [@babblesort](https://discuss.emberjs.com/u/babblesort)
#### Post date: [May 6, 2016, 10:06pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/2 "2016-05-06T22:06:31Z")

</div>

Take a look at yapplab’s [Ember Wormhole](https://github.com/yapplabs/ember-wormhole). Very handy way to redirect render output to another (named by element id) location.

---

<div class="post-metadata">

### Author: ![nullnullnull](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nullnullnull/32/11169_2.png) [@nullnullnull](https://discuss.emberjs.com/u/nullnullnull)
#### Post date: [May 6, 2016, 10:19pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/3 "2016-05-06T22:19:36Z")

</div>

[liquid-tether](https://github.com/pzuraq/liquid-tether) also meets your requirements, and it also exposes animations via liquid-fire.

---

<div class="post-metadata">

### Author: ![Ben\_Glancy](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Ben\_Glancy](https://discuss.emberjs.com/u/Ben_Glancy)
#### Post date: [May 7, 2016, 10:54am UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/4 "2016-05-07T10:54:58Z")

</div>

doesn’t Ember do it on it’s own. Why are we being pushed to third-party stuff which brings with it another load of things to worry about.

---

<div class="post-metadata">

### Author: ![Charles\_Bourasseau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/charles_bourasseau/32/11568_2.png) [@Charles\_Bourasseau](https://discuss.emberjs.com/u/Charles_Bourasseau)
#### Post date: [May 7, 2016, 11:24am UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/5 "2016-05-07T11:24:18Z")

</div>

I feel the same. Third-party stuff just for doing a decent `alert('hello world');`, it could be a joke…

---

<div class="post-metadata">

### Author: ![Ben\_Glancy](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Ben\_Glancy](https://discuss.emberjs.com/u/Ben_Glancy)
#### Post date: [May 7, 2016, 11:26am UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/6 "2016-05-07T11:26:10Z")

</div>

I have the component do a show() on the item container. CSS can set its absolute position and make it an overlay irrelevant of where it is in the DOM.

---

<div class="post-metadata">

### Author: ![Charles\_Bourasseau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/charles_bourasseau/32/11568_2.png) [@Charles\_Bourasseau](https://discuss.emberjs.com/u/Charles_Bourasseau)
#### Post date: [May 7, 2016, 1:08pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/7 "2016-05-07T13:08:52Z")

</div>

Yes but it conflicts with css rules like `position: absolute` or `overflow:hidden` on the parent.

---

<div class="post-metadata">

### Author: ![Ben\_Glancy](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@Ben\_Glancy](https://discuss.emberjs.com/u/Ben_Glancy)
#### Post date: [May 7, 2016, 1:27pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/8 "2016-05-07T13:27:45Z")

</div>

Could you not, on didInsert, have the component change it’s own parent during the lifetime of the overlay? I say this ignorant of how Ember keeps track of the DOM element.

---

<div class="post-metadata">

### Author: ![Charles\_Bourasseau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/charles_bourasseau/32/11568_2.png) [@Charles\_Bourasseau](https://discuss.emberjs.com/u/Charles_Bourasseau)
#### Post date: [May 7, 2016, 7:09pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/9 "2016-05-07T19:09:59Z")

</div>

I’m don’t really want to hack EmberJS. I prefer use a plugin for that.

---

<div class="post-metadata">

### Author: ![Charles\_Bourasseau](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/charles_bourasseau/32/11568_2.png) [@Charles\_Bourasseau](https://discuss.emberjs.com/u/Charles_Bourasseau)
#### Post date: [May 7, 2016, 10:01pm UTC](https://discuss.emberjs.com/t/render-a-component-outside-of-the-template-in-emberjs/10626/10 "2016-05-07T22:01:07Z")

</div>

> [@Ben\_Glancy](#):
>
> Could you not, on didInsert, have the component change it’s own parent during the lifetime of the overlay? I say this ignorant of how Ember keeps track of the DOM element.

This is actually how the Wormhole works: [https://github.com/yapplabs/ember-wormhole/blob/master/addon/components/ember-wormhole.js](https://github.com/yapplabs/ember-wormhole/blob/master/addon/components/ember-wormhole.js)

🙂
