I have a backed api to get a html file content(eg-
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
- In your route’s
modelhook, 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 {
html
};
});
}
- 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>.
Thanks it worked👍 sorry for the late reply