<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/2041/1/7/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics">Include Statements Basics</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~lmadsen">Leif Madsen</a>
</h4>
<div id="versionComment">
<b>Comment:</b>
Update dialplan to use the A:TDG method.<br />
</div>
<br/>
<h4>Changes (9)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-unchanged" >To set the stage for our explanation of include statements, let's say that we want to organize our dialplan and create a new context called *\[docs:features\]*. We'll leave our extensions *6001* and *6002* for Alice and Bob in the *\[docs:users\]* context, and place extensions such as *6500* in the new *\[docs:features\]* context. When calls come into the users context and doesn't find a matching extension, the include statement tells Asterisk to also look in the new *\[docs:features\]* context. <br> <br></td></tr>
<tr><td class="diff-changed-lines" >The syntax for an include statement is very simple. You simply write <span class="diff-changed-words">*include<span class="diff-added-chars"style="background-color: #dfd;"> </span>=>*</span> and then the name of the context you'd like to include from the existing context. If we reorganize our dialplan to add a *\[docs:features\]* context, it might look something like this: <br></td></tr>
<tr><td class="diff-unchanged" >{noformat}[users] <br>include => features <br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6001,1,Dial(SIP/demo-alice,20) <br>exten=>6001,n,VoiceMail(6001@vm-demo,u) <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">exten =>6001,1,Dial(SIP/demo-alice,20) <br> same => n,VoiceMail(6001@vm-demo,u) <br></td></tr>
<tr><td class="diff-unchanged" > <br>exten=>6002,1,Dial(SIP/demo-bob,20) <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6002,n,VoiceMail(6002@vm-demo,u) <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> same => n,VoiceMail(6002@vm-demo,u) <br></td></tr>
<tr><td class="diff-unchanged" > <br>[features] <br>exten=>6000,1,Answer(500) <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6000,2,Playback(hello-world) <br>exten=>6000,3,Hangup() <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> same => n,Playback(hello-world) <br> same => n,Hangup() <br></td></tr>
<tr><td class="diff-unchanged" > <br>exten=>6500,1,Answer(500) <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6500,n,VoiceMailMain(@vm-demo){noformat} <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> same => n,VoiceMailMain(@vm-demo){noformat} <br></td></tr>
<tr><td class="diff-unchanged" >{tip:title=Location of Include Statements }Please note that in the example above, we placed the include statement before extensions *6001* and *6002*. It could have just as well come after. Asterisk will always try to find a matching extension in the current context first, and only follow the include statement to a new context if there isn't anything that matches in the current context.{tip} <br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<p>To set the stage for our explanation of include statements, let's say that we want to organize our dialplan and create a new context called <b>[docs:features]</b>. We'll leave our extensions <b>6001</b> and <b>6002</b> for Alice and Bob in the <b>[docs:users]</b> context, and place extensions such as <b>6500</b> in the new <b>[docs:features]</b> context. When calls come into the users context and doesn't find a matching extension, the include statement tells Asterisk to also look in the new <b>[docs:features]</b> context.</p>
<p>The syntax for an include statement is very simple. You simply write <b>include =></b> and then the name of the context you'd like to include from the existing context. If we reorganize our dialplan to add a <b>[docs:features]</b> context, it might look something like this:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>[users]
include => features
exten =>6001,1,Dial(SIP/demo-alice,20)
same => n,VoiceMail(6001@vm-demo,u)
exten=>6002,1,Dial(SIP/demo-bob,20)
same => n,VoiceMail(6002@vm-demo,u)
[features]
exten=>6000,1,Answer(500)
same => n,Playback(hello-world)
same => n,Hangup()
exten=>6500,1,Answer(500)
same => n,VoiceMailMain(@vm-demo)</pre>
</div></div>
<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Location of Include Statements</b><br />Please note that in the example above, we placed the include statement before extensions <b>6001</b> and <b>6002</b>. It could have just as well come after. Asterisk will always try to find a matching extension in the current context first, and only follow the include statement to a new context if there isn't anything that matches in the current context.</td></tr></table></div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;">
<a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=4817357&revisedVersion=5&originalVersion=4">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>