Ember adapter to get a html file (may contain css,js) and then render the file on a template

I have a backed api to get a html file content(eg-

). My question is where and how to store this html , so that i can able to render the html on the hbs template. I am new to ember Universe so please be kind.:smile:

Hi @light44 could you describe your use case a little more (maybe some snippets or sample requests?) and code format the e.g. you posted above?

Rendering HTML in ember is pretty easy with handlebars (though I wouldn’t describe it as a super common use case) but as for whether you’ll want to use ember data (and therefore an adapter) to fetch the html is a different question. Really depends on your use case and what the content looks like…

I have done what you describe, it’s a pretty reasonable strategy for incrementally adopting Ember.

Assuming you have a server somewhere that gives you HTML and you want to drop that HTML inside an Ember template, you can

  1. In your route’s model hook, get the HTML, something like:
model() {
  return fetch('/your.html').then(response => response.text()).then(html => {
     // this object is the "model" in your template
    return {
  1. Render the HTML in a template via triple curlies:
The server said: {{{model.html}}}

If the server response is a complete page with <head> and <body>, you may want to strip those parts out of the HTML, since that won’t be valid HTML inside your existing <body>.

1 Like

Thanks it worked👍 sorry for the late reply

1 Like