General Interface is an open source project hosted by the Dojo Foundation

Appendix C Contextual Variables

The system provides contextual variables to give additional information that is available only when the template is run. For example, because the system manages layouts, the drawspace changes (decreases) as each nested tag claims its dimensions. In this example, the $$parentwidth field is used to define how much width is available to render within. Each variable listed in the table is available within the <template/> section. This means if you declare a variable (<var/>) or drawspace (<drawspace/>), you can use this value in your calculations.

Contextual Variables
Name Description Sample Use
$$parentwidth provides the width of the containing drawspace Force the next HTML tag to be rendered to be half as small as the available width:
<drawspace width="$$parentwidth * .5"/>

$$parentheight provides the height of the containing drawspace Render the HTML tag10 pixels from the bottom of its container:
<span style="position:absolute;">
  <top>$$parentheight - 10</top>
<span>

The syntax above is not required, but you can use it for greater control over layout. It is more common to simply declare the style inline and have the system automatically handle it, as in the following example:

<span style="position:absolute;top:100%-10;">
</span>

$$target provides a pointer to the active element within a given for-each or attach iteration. If nested loops are used within the template, it is possible to cache this value to avoid collisions Loop through each CDF record and render a div for each one. Use the jsxid from each record in the iteration to generate the id for each div and the jsxtext field for the div text content:
<for-each select="this.getMyRows()">
  <var id="rowid">
     $$target.getAttribute(\'jsxid\')
  </var>
  <var id="rowtext">
     $$target.getAttribute(\'jsxtext\')
  </var>
  <div id="{rowid}">
     <text>{rowtext}</text></div>
</for-each>

A locally declared variable can be used to cache the $$target when doing nested iterations:

<for-each select="this. getMyRows()">
  <var id="rowid">
     $$target.getAttribute(\'jsxid\')
  </var>
  <var id="mytarget">
     $$target</var>
  <div id="{rowid}">
    <for-each select="this. getMyCols()">
      <var id="rowtext">
        mytarget.getAttribute(\'jsxtext\')
      </var>
      <text>{rowtext}</text>
      </for-each>
    </div>
</for-each>


Contents

Searching General Interface Docs

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.