I've created a templated base widget called "Dialog", which I want to use as a core layout widget for all the other within the package. It's a simple container with couple of attach points. (I've not included HTML as it's quite straightforward)
define("my/Dialog",[
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/ready",
"dojo/parser",
"dojo/text!./Dialog.html"], function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, ready, parser, template){
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
widgetsInTemplate: true,
title: 'Dialog',
content: null,
constructor: function(args){
},
postCreate: function(){
this.inherited(arguments);
},
///
/// Getters / Setters
///
_setTitleAttr: function(title){
},
_setContentAttr: function(content){
this._contentPane.innerHTML = content;
}
});
ready(function(){
parser.parse();
});});
Then I want to create another templated dialog that will inherit from this one, and will basically extend it in terms of kind-of-injecting the template into the content of the my/Dialog
define("my/BookmarksDialog",[
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/ready",
"dojo/parser",
"my/Dialog"], function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, ready, parser, Dialog){
return declare([Dialog, _WidgetsInTemplateMixin], {
//templateString: template,
template: '<div data-dojo-attach-point="bookmarkpoint">something</div>',
widgetsInTemplate: true,
content: template, // This works but doesn't parse the widgets within
title: 'Bookmarks',
constructor: function(args){
},
postCreate: function(){
this.inherited(arguments);
}
});
ready(function(){
parser.parse();
});});
The problem I'm facing is that the attach point called bookmarkpoint is not accessible for the BookmarkDialog
So the question is: How do I get the BookmarkDialog template get parsed and placed in the Dialog widget?
Options:
Please note that I'm also firing the .startup() upon instantiating the widget. Thanks
Use buildRendering method, which is designed for this purpose. In this method you can parse templateString property, modify it and then reassign it.
buildRendering: function () {
// Parse template string into xml document using "dojox/xml/parser"
var xml = xmlParser.parse(this.templateString);
var xmlDoc = xml.documentElement;
// Find target node which should be modified
var targetNode = query("div[data-dojo-attach-point='targetNode']", xmlDoc)[0];
// Create new template content using createElement, createAttribute,
// setAttributeNode
var newNode = xml.createElement("button");
// Append content to the xml template
targetNode.appendChild(newNode);
// Re-set the modified template string
this.templateString = xmlParser.innerXML(xmlDoc);
this.inherited(arguments);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With