Render server response to ember main view


(André Karge) #1

Hi,
I retrieve some content from my server and want to render it to the Ember Main View.

Currently I add a div called disraptorView and append via jQuery the Content retrieved from the server controller.
The Problem is: once there is some content in this div it is always displayed when someone is navigating on the page.

I want to render my response to the Ember Main View but I have no idea how to properly do that.

This is my Ember Controller:

export default Ember.Controller.extend({
  init: function() {
    this.send('loadContent');
  },
  actions: {
    loadContent() {
      var pathArray = window.location.pathname.split('/');
      var subpath = pathArray[pathArray.length-1];
      var type;
      type = (subpath == "") ? "main" : "sub";
      Discourse.ajax({
        url: `/disraptor`,
        type: 'GET',
        dataType: 'text',
        data: {"url":subpath,"type":type}
      })
      .then(function(result) {
        $(".disraptorView").empty();
        $(".disraptorView").append($(result));
      })
      .catch(function(error) {
        console.log(error);
      });
    }

  }
});

Here is what it produces:

and when I move to another page on the client:


(Robin Ward) #2

I’m not clear what you mean by this - where do you want your content to appear and when do you want it to go away? If you could show an example we can probably help you better.


(André Karge) #3

I want that my response is rendered in the place where the content for a route is displayed.


(Robin Ward) #4

I suggest you look at the discourse-adplugin for an example of how to create a component that is displayed on every “page” of discourse.


(André Karge) #5

Ah thanks, that helped a lot.
I forgot that there are outlets to do that stuff …


(Robin Ward) #6