Search code examples
javascriptdojodoh

doh Hello World with templated widget that mixin's ContentPane


I am trying to get a sample doh test case running. I am testing a templated widget that mixins from dijit/layout/ContentPane.

No error is being thrown...the component simply doesn't render. The template file is being loaded because I can see it in the net tab of firebug, but it's like it's not being "attached" to the templated widget. When I remove the ContentPane mixin, things work as expected.

Our project uses ContentPane to mixin to our templated widgets in many places so we can treat our widget as a layout widget. The problem only occurs when trying to load it with the doh.

The widget we're trying to load:

define([
    'dijit/layout/ContentPane',
    'dijit/_WidgetsInTemplateMixin',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetBase',
    'dojo/_base/declare',
    'dojo/text!./about.html'
    ], function(ContentPane, WidgetsInTemplateMixin, TemplatedMixin, WidgetBase, declare, about) {
    return declare([ContentPane, TemplatedMixin, WidgetsInTemplateMixin], {
        templateString: about,

        constructor: function() {
            this.inherited(arguments);
        },

        startup: function() {
            this.inherited(arguments);
        }
    });
});

The template:

<div>
    <div>
        <h1>foo</h1>
    </div>
</div>

The doh test runner page:

<body class="claro">
    <div style="height: 100%">
    <div id="mainContainer"
         style="height: 100%; width: 100%"
         data-dojo-type="dijit/layout/BorderContainer">
        <div data-dojo-type="dijit/layout/ContentPane"
             data-dojo-props="region: 'center'">
            <div data-dojo-type="testPackage/widgets/About/About"
                 style="width: 100px; height: 100px; background-color: green">
            </div>
        </div>
    </div>
    </div>

    <script type="text/javascript">
        require([
            'dojo/ready',
            'dojo/parser',
            'dojo/dom-style',
            'dojo/query',
            'dojo',
            'doh'
        ], function(ready, parser, domStyle, query, dojo, doh){
            ready(function() {
                parser.parse();

                doh.register("t", [
                        function setup(t){
                            var d = new doh.Deferred();

                            d.callback(true);
                            return d;
                        }
                    ]
                );
                doh.run();
            });
        });
    </script>
</body>

The "foo" text in the template html file is not shown


Solution

  • "so we can treat our widget as a layout widget"...

    You should mixin dijit/_LayoutWidget instead of dijit/layout/ContentPane if all you want to get is the layout functionality.

    So, your widget would become :

    define([
         'dijit/layout/_LayoutWidget',
        'dijit/_WidgetsInTemplateMixin',
        'dijit/_TemplatedMixin',
        'dojo/_base/declare',
        'dojo/text!./about.html',
        'dojo/domReady!'
    ], function(ContentPane, _WidgetsInTemplateMixin, _TemplatedMixin, declare, about) {
        return declare([_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
    
            templateString: about,
    
            // ...
        });
    });