I'd like to extend a custom widget that I already have, but I'm a bit confused about how the templates between the super and sub class are related. For example, suppose I have a dialog class and would like to create an extension to that class that adds a toolbar to the bottom of the dialog. How can I write the subclass template so that it inherits the superclass template but adds the additional toolbar? I searched the site but couldn't find any real-world examples of this. There's an example of extending the Accordion container, but it appears as though the author simply copied the superclass template and modified it for his new widget. I'm hoping there's a better way...
Extending a widget - how are the templates composed?
Submitted by wisbang on Wed, 05/07/2008 - 22:00.
- Login or register to post comments
- Unsubscribe post

not in dijit, but...
There's no template inheritance as such in Dijit. If you really wanted to do this, probably what you'd do is override buildRendering (defined in _Templated.js)
Yes, the normal practice is to define your new template string/file, probably starting with the original as a guide. But, the widget system just wants a string when it comes down to it - you can make that string ahead of time any way you like.
e.g.
dojo.declare("my.Dialog", [dijit.Dialog], {
templateString: dijitDialogTemplateString.replace(/<\/div>$/, "<div>more stuff</div></div>"
});
I've used replace to inject the new stuff inside the outer div - the template needs to all be contained in one element (the domNode).
If you want to understand Dijit's templates, look at _Template.js, the buildRendering method in particular.
Sam
Thanks for the reply and
Thanks for the reply and pointer. I'll check out _Template.js.