System information
More Advanced Digit Manipulation
The ${EXTEN} variable properly has the syntax ${EXTEN:x:y}, where x is the starting po-
sition and y is the number of digits to return. Given the following dial string:
94169671111
we can extract the following digit strings using the ${EXTEN:x:y} construct:
• ${EXTEN:1:3} would contain 416
• ${EXTEN:4:7} would contain 9671111
• ${EXTEN:-4:4} would start four digits from the end and return four digits, giving
us 1111
• ${EXTEN:2:-4} would start two digits in and exclude the last four digits, giving us
16967
• ${EXTEN:-6:-4} would start six digits from the end and exclude the last four digits,
giving us 67
• ${EXTEN:1} would give us everything after the first digit, or 4169671111 (if the num-
ber of digits to return is left blank, it will return the entire remaining string)
This is a very powerful construct, but most of these variations are not very common in
normal use. For the most part, you will be using ${EXTEN} (or perhaps ${EXTEN:1} if you
need to strip off an external access code).
Includes
Asterisk has an important feature that allows extensions from one context to be avail-
able from within another context. This is accomplished through use of the include
directive. The include directive allows us to control access to different sections of the
dialplan.
The include statement takes the following form, where context is the name of the
remote context we want to include in the current context:
include => context
Including one context within another context allows extensions within the included
context to be dialable.
When we include other contexts within our current context, we have to be mindful of
the order in which we are including them. Asterisk will first try to match the dialed
extension in the current context. If unsuccessful, it will then try the first included con-
text (including any contexts included in that context), and then continue to the other
included contexts in the order in which they were included.
We will discuss the include directive more in Chapter 7.
Building an Interactive Dialplan | 129