<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>
Make<br />
</div>
<br/>
<h4>Changes (4)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" > same => n,VoiceMail(6001@vm-demo,u) <br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6002,1,Dial(SIP/demo-bob,20) <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">exten => 6002,1,Dial(SIP/demo-bob,20) <br></td></tr>
<tr><td class="diff-unchanged" > same => n,VoiceMail(6002@vm-demo,u) <br> <br>[features] <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">exten=>6000,1,Answer(500) <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">exten => 6000,1,Answer(500) <br></td></tr>
<tr><td class="diff-unchanged" > same => n,Playback(hello-world) <br> same => n,Hangup() <br></td></tr>
<tr><td class="diff-snipped" >...<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=6&originalVersion=5">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>