# Detect template render in controller?

**URL:** https://discuss.emberjs.com/t/detect-template-render-in-controller/6253
**Category:** Uncategorized
**Created:** [September 12, 2014, 4:36pm UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253 "2014-09-12T16:36:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![emorling](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/emorling/32/9484_2.png) [@emorling](https://discuss.emberjs.com/u/emorling)
#### Post date: [September 12, 2014, 4:36pm UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253/1 "2014-09-12T16:36:58Z")

</div>

How do I detect when a template tied to a controller has been rendered?

I need to initialize a jQuery plugin.

I tried init() and reopen() in the controller without luck.

Ideas?

---

<div class="post-metadata">

### Author: ![samselikoff](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/samselikoff/32/16581_2.png) [@samselikoff](https://discuss.emberjs.com/u/samselikoff)
#### Post date: [September 12, 2014, 4:44pm UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253/2 "2014-09-12T16:44:11Z")

</div>

Try `didInsertElement` on the **view** (not controller) backing the template.

i.e.

```
App.PostsView = Ember.View.extend({
  didInsertElement: function() {
    this.$().magic();
  }
});

```

for the posts template

---

<div class="post-metadata">

### Author: ![emorling](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/emorling/32/9484_2.png) [@emorling](https://discuss.emberjs.com/u/emorling)
#### Post date: [September 12, 2014, 7:12pm UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253/3 "2014-09-12T19:12:43Z")

</div>

Thanks! Works like a charm

---

<div class="post-metadata">

### Author: ![zzarcon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/zzarcon/32/15279_2.png) [@zzarcon](https://discuss.emberjs.com/u/zzarcon)
#### Post date: [September 19, 2014, 7:26am UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253/4 "2014-09-19T07:26:47Z")

</div>

I think that using event oriented for this is a better approach:

```auto
setupPlugin: function() {
   this.$().magic();
}.on('didInsertElement')

```

By this way you don’t have to call `this._super(arguments)` in the redefinition of `didInsertElement`, what do you think @samselikoff?

---

<div class="post-metadata">

### Author: ![samselikoff](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/samselikoff/32/16581_2.png) [@samselikoff](https://discuss.emberjs.com/u/samselikoff)
#### Post date: [September 19, 2014, 2:19pm UTC](https://discuss.emberjs.com/t/detect-template-render-in-controller/6253/5 "2014-09-19T14:19:11Z")

</div>

I actually usually do this too, I think the naming is clearer.

The only time I’ve run into `super` trouble is with `init`, don’t think you need to with `didInsertElement`. But, doing it this way is safer regardless, so I like it.
