Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember js : load multiple template on one page with data

Tags:

ember.js

I am working on a application in ember.js . I have an few questions to all of you guys. First lets discuss about my application points and then what problem I am facing in.

  1. Application is about something like a drawing a plans like a "auto cad ". For this purpose I am using d3.js library
  2. For a drawing purpose we have different sections like Fire, Water, etc..Satelite All of this sections have different svg container for drawing.
  3. After this things I have one module for email this sections to a particular email id in three ways

    3.1 Current Section wise email (Means if we drawing in a fire section then If we send email then svg of fire section will send as a form of pdf) (Done)

    3.2 At a time all the sections svg content in PDF. (Here my actual problem starts)

In this point all sections email I am getting problem in retrieve all section svg's at a time. Because the current section is already loaded in a view, template with data , But how can I get all the sections template with its drawing data (svg element's).

I created my route like this

emailPDF = Ember.Route.extend({

    setupController: function(controller, model)
    {
        alert("Controller setup");
        this.controllerFor('fire').set('model', model);
        this.controllerFor('gas').set('model', model);
    },
    renderTemplate: function() {
        this._super();
        this.render('fire', {           // the template to render
            into: 'emailPDF',       // the template to render into
            outlet: 'fire',              // the name of the outlet in that template
            controller: 'fire'        // the controller to use for the template
        });
        this.render('gas', {
            into: 'emailPDF',
            outlet: 'gas',
            controller: 'gas'
        });
    }
});

And the template is like :

<div id="fire_test">
    {{outlet 'fire'}}
</div>
<div id="gas_test">
    {{outlet 'gas'}}
</div>

Then I transition this route from one controller like this :

this.transitionToRoute('emailPDF');

But here in the allSections template I am getting previous template that I have already open in the place of fire and gas outlet not able to render fire and gas template.

Please tell me if i am doing something wrong...

like image 580
Rahul_Dabhi Avatar asked May 05 '15 13:05

Rahul_Dabhi


1 Answers

I believe what you want to do here is something like this... You need to create a route, say HomeAndContact. In this route create a template. You have 2 options here, make the template something like:

{{outlet 'home'}}
{{outlet 'contact'}}

Or you could also just do:

{{render 'home'}}
{{render 'contact'}}

I would advise against the second option because it will be deprecated/is not aligned with what Ember is doing going forward.

To do the first option, you will need to have some code like this in your HomeAndContactRoute:

HomeAndContactRoute = Ember.Route.extend({
  setupController: function(controller, model) {
    this.controllerFor('home').set('model', model);
    this.controllerFor('contact').set('model', model);
  },
  renderTemplate: function() {
    this.render('home', {           // the template to render
      into: 'homeAndContact',       // the template to render into
      outlet: 'home',              // the name of the outlet in that template
      controller: 'home'        // the controller to use for the template
    });
    this.render('contact', {
      into: 'homeAndContact',
      outlet: 'contact',
      controller: 'contact'
    });
  }
});

I hope this helps.

like image 58
bmeyers Avatar answered Nov 17 '22 23:11

bmeyers