HDML variables are named pieces of information that the phone substitutes into HDML at runtime. They allow you to write HDML that dynamically changes display content and navigation based on user input. You can set variables explicitly, or you can allow the user to set them with choice or entry cards. You can substitute variable values into display text and certain HDML options such as the DEST (destination) option.
There are relatively few guidelines for variable naming:
$, <, >, =, /, \, &, *, #
myvar and Myvar are two different variables
Variables are scoped to activities. You can reference a variable anywhere within the activity in which it is set; you can't reference it in other activities.
The VARS task option allows you to set a list of variables when you navigate from one card to another. For example, the following deck includes a display card which sets the value of two variables when the user presses ACCEPT. A second display card displays the variable values.
3.0>
You capture user input to a variable by specifying the variable's name in the KEY option of a choice or entry card. For example, the following HDML defines an entry card that stores the user's input to a variable named usrname.
3.0 MARKABLE=false>You can substitute variable values into the following:
HDML variable substitution is much like UNIX shell variable substitution. The following table describes the methods of substituting variable values:
For example, the following HDML allows the user to set a variable in an entry card; it then substitutes the variable's value in the display text of another card. Figure 1-10 displays the resulting interface.
3.0 MARKABLE=false>FIGURE 1-10. Setting and substituting variable values
In most cases, you do not need to specify the esc or noesc options. The phone substitutes the variable using the conversion appropriate for the context. Specifically, the phone uses URL escaping when you specify a variable in the following options:
By default, the phone does not use URL escaping in any other context.
There are a few cases when you might need to specify the esc or noesc options. For example, If you use a variable to specify a full destination URL, you must use the noesc option. If you do not, the phone will include escape characters when it inserts the variable value, which will result in an invalid, doubly-escaped URL. For example, the following HDML displays a card that allows the user to enter the URL of an HDML service. When the user presses ACCEPT, the phone requests the URL that the user entered.
3.0>FIGURE 1-11. Setting and substituting variable values
If you did not use the noesc option to substitute the variable value, the phone would request the following, invalid URL:
HDML provides several mechanisms to pass variable information between activities:
VARS option (with the GOSUB task) to set variable values for a nested activity
RECEIVE option to specify variables that accept return values from the nested activity; the nested activity uses the RETVALS option to return values to these variables
CLEAR option to unset all the variables of the activity that called it.