O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The <template> Element

The <template> element provides an interesting WML feature not found in HTML. When you write a deck containing several cards, you may find that parts of the structure are common to all the cards. For example, it’s fairly typical for each card to have a “back” control and a “home” control. These controls are normally implemented as <do> elements. It would be convenient to specify these common elements once per deck rather than once per card, and that is just what the <template> element allows.

It doesn’t stop there, though. Remember all those card events from Chapter 3? Wouldn’t it be easier to set up bindings for all the events just once for the whole deck? That would certainly save wear and tear on your fingers (or at least your cut-and-paste keys), and since WAP is supposed to be optimized for low bandwidth, it’s a waste of time to have to send all that duplicated information. As you might have guessed, the <template> element allows this, too.

You may be wondering what happens if you want a control on most, but not all, of the cards in a deck, or if you want an event binding to apply to just some of the cards. The good news is that this case has also been anticipated: any individual card can override the deck-level settings with its own, or even remove controls or event bindings altogether. This process of overriding is known as shadowing (see the next section for an explanation of shadowing).

The <template> element can contain any number of <do> elements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required