I am using a dojo template project for my applications, and this is my main.js :
define([ 'dojo/has', 'require', 'dojo/_base/sniff' ], function (has, require) { var app = {}; if (has('host-browser') && isCompatible()) { require([ './EntryPoint', 'dojo/domReady!' ], function (EntryPoint) { app.entryPoint = new EntryPoint().placeAt(document.body); app.entryPoint.startup(); } else { window.location = "/admin/browser/"; } function isCompatible() {
My EntryPoint module / class is a widget, i.e. EntryPoint.js as follows:
define([ "dojo/_base/declare", "dijit/_Widget", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", "dojo/i18n!app/nls/main", "dojo/text!./ui/templates/EntryPoint.html", "dijit/layout/BorderContainer", "dijit/layout/StackContainer", "dijit/layout/ContentPane" ], function( declare, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, i18n, template ){ return declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], { templateString: template, i18n: i18n, postCreate: function() {
Finally, my EntryPoint.html :
<div style="height:100%;"> <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: 'sidebar', gutters: false" data-dojo-attach-point="mainContainer" style="height:100%;" > <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="region: 'left', splitter: true, design: 'headline', gutters: false" data-dojo-attach-point="sidebarPane" class="sidebarPane" > <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'center'" > <div class="sidebarSection">${i18n.title.public_}</div> <div id="sidebar-posts" data-dojo-type="app.widget.SidebarItem" data-dojo-props="iconClass: 'sidebarIconPosts', value:'posts', name: 'sidebar'"> ${i18n.title.posts} </div> <div id="sidebar-pages" data-dojo-type="app.widget.SidebarItem" data-dojo-props="iconClass: 'sidebarIconPages', value:'pages', name: 'sidebar'"> ${i18n.title.pages} </div> [...]
The advantage of using Widget as the main layout:
- html template works out of the box using dojo build system
- you can use
data-dojo-attach-point and data-dojo-attach-event in the layout template - you can use
${i18n.title.members} to string substitution in html