Blaze dynamic Import


#1

Hi All,

Below is homepage.html (parent template)

<template name="homepage">
      Homepage Content
     {{> Template.dynamic template=content}}	
</template>

login.html (child template)

<template name="login">
	You're logged in!
</template>

login.js

import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';

import '../homepage/homepage.js';
import './login.html';
API = function () {
    Blaze.render(Template.homepage, document.body);
}

export { API }
openLogin = function () {
    import('/imports/modules/common/login/login.js').then(function (api) {
        api.API();
    })
}

/lib/route.js

import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
FlowRouter.route('/', {
  name: 'homepage',
  action() {
    openLogin();
  }
});

Here I am able to see Homepage content but I wants to load login template dynamically through hompage template.
Thanks in advance!


#2

Use Blaze.renderWithData

API = function () {
    Blaze.renderWithData(Template.homepage, { content: 'login' }, document.body);
}

In your homepage template, you’re telling Template.dynamic to render a template who’s name is defined by the variable content in your data context. So you need to set the value of content and pass that data context into your homepage