.. _dijit/Declaration: dijit.Declaration ================= :Status: Draft :Version: 1.0 :Project owner: Bill Keese :Available: since V1.2 .. contents:: :depth: 2 Declares a widget from markup. ============ Introduction ============ Just as there are two ways to create a widget instances - declarative and programmatic - so there are two ways to declare a Dijit class (i.e., a type of widget). As you might guess, the declarative way is slightly easier. ===== Usage ===== To declare your class declaratively, use dijit.Declaration. Uhhhh, OK, too many "declare"s in that sentence. It's easier to show than to tell. Here's an example defining a widget called Employee, and then creating two of those Employee widgets: .. cv-compound:: .. cv:: javascript .. cv :: html
${name} update delete
Note that it's defining two widget parameters: * empid: Number * name: String And then it's defining a template .. code-block:: html ${name} update delete And finally that it's using the widget parameters name and empid in the template, as the substitution variables ${name} and ${empid}. Dijit.Declaration turns this markup into a templated widget class. The code doesn't display anything itself, so it's best to place it right after the BODY tag before any displayable code. Methods, dojoAttachPoint, and dojoAttachEvent --------------------------------------------- The example below defines a widget named "HideButton" that will hide itself when clicked, and then creates two HideButtons: .. cv:: html
XXXXXX
A few things to note here: * using the Every widget declared with class simpleConnectedWidget will have the handler connected to it. Note that dojo/connect is not suitable for methods that need to return a value. ===== Notes ===== - widgetsInTemplate is automatically set to true, so any widgets you place in the template will be automatically filled in. - If you do not specify mixin, the widget class will be a subclass of :ref:`dijit._Widget ` and mix in :ref:`dijit._Templated `. If you specify mixin, the first class listed must be a subclass of :ref:`dijit._Widget `. At least one of the mixins should itself mixin :ref:`dijit._Templated `, or you should supply :ref:`dijit._Templated ` yourself as a mixin. - Only one extension point implementation of preamble.