# Allow user to provide customized template for component rendering

**URL:** <https://discuss.emberjs.com/t/allow-user-to-provide-customized-template-for-component-rendering/9072>\
**Category:** Uncategorized\
**Created:** [November 9, 2015, 7:38am UTC](https://discuss.emberjs.com/t/allow-user-to-provide-customized-template-for-component-rendering/9072 "2015-11-09T07:38:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)\
**Post date:** [November 9, 2015, 7:38am UTC](https://discuss.emberjs.com/t/allow-user-to-provide-customized-template-for-component-rendering/9072/1 "2015-11-09T07:38:43Z")

</div>

I’m trying to solve a tricky problem, so I’ve made a twiddle to demonstrate it:

> **[Ember Twiddle](https://ember-twiddle.com/#/8749ee21c350a97d9d87)**
>
> A web-based Ember.js code sharing tool that follows ember-cli's conventions.

Here’s my problem, basic idea is to allow consumers define template of each selection and selected item for component, so I exposed the each selection for {{auto-complete-datalist}} and current selected item for {{auto-complete-input}}. Since we need to control how to render them (use customized HTML tags), so I have to use a `div` with `contenteditable=true`.

Now, you can focus in the input, select an option, then display the result as user defined form. But! you can’t _DELETE_ the current selected item! because if you do that, you will also delete the customized template, so it won’t show again after deletions.

I don’t know how to archive this goal, many similar plugins will use a template option which allow user to provide a string HTML fragment, the plugin will render this at the runtime. It seems like a accept way but I don’t know how to allow consumers provide a string HTML template with handlebars tags in it?

How will you make this happen? Any suggestions will be appreciated.

---

<div class="post-metadata">

**Author:** ![lightblade](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/lightblade/32/15632_2.png) [@lightblade](https://discuss.emberjs.com/u/lightblade)\
**Post date:** [November 10, 2015, 5:42pm UTC](https://discuss.emberjs.com/t/allow-user-to-provide-customized-template-for-component-rendering/9072/2 "2015-11-10T17:42:40Z")

</div>

It’s not just delete the input content. Even if you just modify the content, that piece just stop getting change.

I think the problem could be in `contenteditable`. You _are_ editing the DOM directly and that could mess with HTMLBars’ morph nodes. So what we need is to teardown the inner DOM completely (bypass whatever Glimmer is doing) and rerender the whole thing. There may be performance overhead, but I think it’s very minor since you’re not rendering a big piece.

Take a look [Ember Twiddle](https://ember-twiddle.com/112934491b501fc2d270)

---

<div class="post-metadata">

**Author:** ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)\
**Post date:** [November 12, 2015, 9:32am UTC](https://discuss.emberjs.com/t/allow-user-to-provide-customized-template-for-component-rendering/9072/3 "2015-11-12T09:32:39Z")

</div>

Thank you very much, now I clearly understand how it works!
