docs: function (cfg) {
              if (!ariaCoreJsonValidator.normalize({
                  json : cfg,
                  beanName : "aria.templates.CfgBeans.InitTemplateCfg"
              })) {
                  return false;
              }
              this._out = null;
              this._cfg = cfg;
              if (cfg.id) {
                  this._id = cfg.id;
              } else {
                  this._id = "tpl" + idCount;
                  idCount++;
              }
  
              if (Aria.testMode) {
                  this._prefixIds = {};
              }
  
              // if the template has been customized, the widget returns already the actual (customized) classpath
              this.tplClasspath = cfg.classpath;
  
              // TODO: check if cfg.classpath corresponds to a template is a template
              var tpl;
              try {
                  tpl = Aria.getClassInstance(cfg.classpath);
              } catch (e) {
                  this.$logError(this.TEMPLATE_CONSTR_ERROR, [cfg.classpath], e);
                  return false;
              }
              this._tpl = tpl;
  
              // set the macro after tpl
              if (cfg.macro == null) {
                  cfg.macro = {
                      name : "main",
                      args : cfg.args,
                      scope : tpl
                  };
              }
              cfg.macro = this.checkMacro(cfg.macro);
  
              // PTR05228660: use private interface for performances
              var context = cfg.context, moduleCtrl = cfg.moduleCtrl, data = cfg.data;
              var privateInfo, moduleCtrlPrivate;
  
              // retrieve information from context if not specified
              if (context && !moduleCtrl) {
                  if (!data) {
                      data = context.data;
                  }
                  moduleCtrl = context.moduleCtrl;
              }
  
              if (moduleCtrl) {
                  // When a moduleCtrl is used, the ModuleCtrlFactory should be loaded.
                  // However, the ModuleCtrlFactory is not a static dependency cause sometimes we don't need it.
                  // TODO: today, we just fail if it's not here, replace this with a silent dynamic loading
                  // (Aria.load)
                  if (!aria.templates.ModuleCtrlFactory) {
                      this.$logError(this.MISSING_MODULE_CTRL_FACTORY, [cfg.classpath]);
                  } else {
  
                      if (!__getModulePrivateInfo) {
                          __getModulePrivateInfo = aria.templates.ModuleCtrlFactory.__getModulePrivateInfoMethod();
                      }
                      privateInfo = __getModulePrivateInfo.call(this, moduleCtrl);
  
                      if (!privateInfo) {
                          // if privateInfo is null, it means either the module controller was not created through
                          // aria.templates.ModuleCtrlFactory or it was already disposed (error was already logged in
                          // __getModulePrivateInfo)
                          return false;
                      }
                      moduleCtrlPrivate = privateInfo.moduleCtrlPrivate;
  
                      if (!data) {
                          data = moduleCtrlPrivate.getData();
                      } else {
                          // data where specified. If a context was also specified, try to match data with a sub
                          // controller
                          if (context) {
                              var newModuleCtrl = moduleCtrlPrivate.getSubModuleCtrl(data);
                              if (newModuleCtrl != moduleCtrl) {
                                  moduleCtrl = newModuleCtrl;
                                  // update moduleCtrl info
                                  privateInfo = __getModulePrivateInfo.call(this, moduleCtrl);
                                  if (!privateInfo) {
                                      // if privateInfo is null, it means either the module controller was not created
                                      // through aria.templates.ModuleCtrlFactory or it was already disposed (error
                                      // was already logged in __getModulePrivateInfo)
                                      return false;
                                  }
                                  moduleCtrlPrivate = privateInfo.moduleCtrlPrivate;
                              }
                          }
                      }
                  }
              }
  
              this.data = data;
              this.moduleCtrl = moduleCtrl;
              if (privateInfo) {
                  this.flowCtrl = privateInfo.flowCtrl;
                  this.flowCtrlPrivate = privateInfo.flowCtrlPrivate;
                  this.moduleCtrlPrivate = moduleCtrlPrivate;
                  this.moduleRes = moduleCtrlPrivate.getResourceSet();
              }
  
              // update configuration
              cfg.data = data;
              cfg.moduleCtrl = moduleCtrl;
  
              // register this template in the templateCtxtManager
              ariaTemplatesTemplateCtxtManager.add(this);
  
              if (this.data != null) {
                  this.__dataGround = {
                      data : this.data
                  };
              }
  
              // We no longer create new methods in a closure each time a new instance of a template is created,
              // instead we use the interface mechanism to expose methods to the template and prevent access to the
              // template context
              // LEAK & PERF IMPROVMENT : interface on these two functions results in poor performance and leaks
  
              var oSelf = this, index, name;
  
              for (index = 0; name = paramMapping[index]; index++) {
                  tpl[name] = this[name];
              }
  
              var functionUtils = ariaUtilsFunction;
              for (index = 0; name = methodMapping[index]; index++) {
                  tpl[name] = functionUtils.bind(this[name], this);
              }
  
              // do not use bind for __$write as this method is called intensively (Perf improvment)
              tpl.__$write = function (s, line) {
                  return oSelf.__$write(s, line, this.$classpath);
              };
  
              if (this.moduleCtrl) {
                  this.moduleCtrl.$on({
                      '*' : {
                          fn : tpl.onModuleEvent,
                          scope : tpl
                      },
                      'beforeDispose' : {
                          fn : this._beforeModuleDispose,
                          scope : this
                      }
                  });
              }
              if (this.flowCtrl) {
                  this.flowCtrl.$on({
                      '*' : tpl.onFlowEvent,
                      scope : tpl
                  });
              }
  
              this._width = {};
              this._height = {};
              this.$setViewportWidth(ariaTemplatesLayout.realWidth(cfg.width));
              this.$setViewportHeight(ariaTemplatesLayout.realHeight(cfg.height));
              this.$setSizeCfg(tpl.__$width, tpl.__$height);
              this.__addDebugInfo(cfg.tplDiv);
              var res = tpl.__$initTemplate();
              this.__loadLibs(tpl.__$macrolibs, "macrolibs");
              return res;
          }