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.
|
Feedback Form (ExpandCollapse)
|
|