The Parser
The Dojo parser is a Core resource that is the standard means of
instantiating a widget defined in markup and ensuring that its visible
representation, linked via its domNode, gets inserted into the page. Once
the domNode is assigned into the
page, the browser renders it on the page. So, while a widget's DOM
node is the vital part of the dijit that makes it visible, the
totality of the dijit is considerably more. This section provides an
introduction to the parser, as well as play-by-play coverage on
exactly how it works.
Parsing a Widget When the Page Loads
Aside from seeing some references in the introductory material in Chapter 1 and some exposure in the drag-and-drop examples from Chapter 7, the parser hasn't been formally introduced because its most common use case is instantiating widgets in a page. Without further ado, here's an official example of the parser instantiating a widget from markup. Note the emphasized lines in Example 11-2, which highlight where the parser-related action is happening.
Example 11-2. Automatically parsing a widget
<html>
<head>
<title>Fun With the Parser!</title>
<!-- pull in the standard CSS that styles the stock dijits -->
<link rel="stylesheet" type="text/css"
href="http://o.aolcdn.com/dojo/1.1/dojo/resources/dojo.css" />
<link rel="stylesheet" type="text/css"
href="http://o.aolcdn.com/dojo/1.1/dijit/themes/tundra/tundra.css" />
<script
type="text/javascript"
src="http://o.aolcdn.com/dojo/1.1/dojo/dojo.xd.js"
djConfig="parseOnLoad:true" ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access