13. WML Template and Menu
In this section, we will introduce to you a new WML tag -- <template>. It is used to apply <do> and <onevent> elements to all cards in a deck. (We will discuss the <onevent> element in detail when we cover events later in this WML tutorial.)
In many web sites, the most commonly used links are grouped together in a menu and placed on the left side or at the top of the web pages. Users can navigate between the web pages conveniently with such kind of menu.
In WML, we can use the <do> element to create similar menus, which contain the most important and commonly used links of a mobile Internet site. What we need to do is to make the <do> elements accessible on all cards. One way is to include the same <do> elements in every card, like this:
<card
id="card1">
<do name="a1"
type="accept" label="link 1">
<go
href="link1.wml"/>
</do>
<do
name="a2" type="accept" label="link
2">
<go
href="link2.wml"/>
</do>
...
</card>
<card
id="card2">
<do name="a1"
type="accept" label="link 1">
<go
href="link1.wml"/>
</do>
<do
name="a2" type="accept" label="link
2">
<go
href="link2.wml"/>
</do>
...
</card>
<card
id="card3">
<do name="a1"
type="accept" label="link 1">
<go
href="link1.wml"/>
</do>
<do
name="a2" type="accept" label="link
2">
<go href="link2.wml"/>
</do>
...
</card>
Obviously, the above way has many drawbacks. For example, it increases the size of the WML document rapidly and thus increases the download time. Also, if we want to change the menu, we need to make changes to every WML card.
A better way is to define deck-level <do> elements using the <template> element. Deck-level <do> elements are enclosed within <template></template>. WAP browsers will apply the <do> elements in a template to all cards in a deck.
With the <template> tag, the previous WML markup can be rewritten as follows:
<template>
<do
name="a1" type="accept" label="link
1">
<go href="link1.wml"/>
</do>
<do
name="a2" type="accept" label="link
2">
<go
href="link2.wml"/>
</do>
...
</template>
<card
id="card1">
...
</card>
<card
id="card2">
...
</card>
<card
id="card3">
...
</card>
You can override a <do> element of a template by defining another <do> element with the same name attribute value in a WML card.
Previous Page | Page 25 of 50 | Next Page |
- 1. WML (Wireless Markup Language) Introduction
- 2. WML Deck and Card
- 3. WML Document Structure
- 4. WML Generic Metadata: <meta>
- 5. Comments in WML
- 6. Line Breaking in WML
- 7. Font Size and Style in WML
- 8. WML Preformatted Text: <pre>
- 9. WML Images
- 10. WML Tables
- 11. WML Anchor Links
- 12. Programming Softkeys of Mobile Phones and the <do> Element
- 13. WML Template and Menu
- 14. WML Events and the <onevent> Tag
- 15. Timer and the ontimer Event
- 16. WML Event: onenterbackward
- 17. WML Event: onenterforward
- 18. WML Selection Lists and the onpick Event
- 19. WML Input Fields
- 20. WML Variables
- 21. Submitting Form Data to the Server in WML
- 22. Clearing a Saved Form in WML