WML Tutorial on WML Template

the <template> is used to apply <do> and <onevent> elements to all cards in a deck. this element defines a template for all the cards in a deck and the code in the <template> tag is added to each card in the deck.

you can override a <do> element of a template by defining another <do> element with the same name attribute value in a wml card.

the <template> element supports the following attributes:

attribute value description
onenterbackward url occurs when the user navigates into a card using a "prev" task
onenterforward url occurs when the user navigates into a card using a "go" task
ontimer url occurs when the "timer" expires
class class data sets a class name for the element.
id element id a unique id for the element.

following is the example showing usage of <go> element.

<?xml version="1.0"?>
<!doctype wml public "-//wapforum//dtd wml 1.3//en" 
"http://www.wapforum.org/dtd/wml13.dtd">

<wml>
  <template>
    <do name="main_menu" type="accept" label="chapters">
      <go href="chapters"/>
    </do>
    <do name="menu_1" type="accept" label="chapter 1">
      <go href="#chapter1"/>
    </do>
    <do name="menu_2" type="accept" label="chapter 2">
      <go href="#chapter2"/>
    </do>
    <do name="menu_3" type="accept" label="chapter 3">
      <go href="#chapter3"/>
    </do>
    <do name="menu_4" type="accept" label="chapter 4">
      <go href="#chapter4"/>
    </do>
  </template>

  <card id="chapters" title="wml tutorial">
    <p>
      select one chapter:<br/>
      <anchor>
        <go href="#chapter1"/>
        chapter 1: wml overview
      </anchor><br />

      <anchor>
        <go href="#chapter2"/>
        chapter 2: wml environment
      </anchor><br />

      <anchor>
        <go href="#chapter3"/>
        chapter 3: wml syntax
      </anchor><br />

      <anchor>
        <go href="#chapter4"/>
        chapter 4: wml elements
      </anchor><br />
    </p>
  </card>

  <card id="chapter1" title="wml tutorial ch1">
    <p>
      <em>chapter 1: wml introduction</em><br/>
      ...
    </p>
  </card>

  <card id="chapter2" title="wml tutorial ch2">
    <p>
      <em>chapter 2: wml environment</em><br/>
      ...
    </p>
  </card>

  <card id="chapter3" title="wml tutorial ch3">
    <p>
      <em>chapter 3: wml syntax</em><br/>
      ...
    </p>
  </card>

  <card id="chapter4" title="wml tutorial ch4">
    <p>
      <em>chapter 4: wml elements</em><br/>
      ...
    </p>
  </card>
</wml>

this will produce the following menu and now you can navigate through all the chapters:

wap example 11