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

Chapter 2. WML Variables and Contexts

A significant difference between WML and HTML is that WML supports variables. WML variables contain strings, and these strings can be inserted into the body text of the WML document or into the values of certain attributes. The values of variables can be changed under the control of the WML itself and also from within WMLScript functions (more on these later).

The names of WML variables can consist of any combination of letters, digits, and underscores, except that the first character must not be a digit. Like most things in WML, variable names are case-sensitive. The following are all examples of legal variable names:

a
foo
__name_with_underscores__  _
ThisVariableNameIsImpracticalBecauseItIsTooLong
xy17

The following are examples of invalid variable names:

17xy                   (starts with a digit)


name with spaces       (space is not a letter, digit, or underscore)

Although WML doesn’t impose a limit on the length of variable names, remember that the full name needs to be transmitted over a low-bandwidth link and then stored in the (possibly limited) memory on the device running the browser. As a result, it’s a good idea to keep your variable names short.

Variable Substitution

Variables can be inserted (or substituted ) into the body text or an attribute value in one of three ways:

$name
$(name)
$(name:conversion)

If the first form is used, the variable name must be followed by some character that’s illegal in variable names (any character other than a letter, digit, or ...

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