Hi, Does anyone have a clever method of doing a conditional "include =>" line in the dialplan? I want to include a bunch of standard contexts, but in the middle of the bunch have one or more conditionally included, a bit like: [default] include => start-here include => then-here if $[{COMPANY} = A] include => company-A endif if $[{COMPANY} = B] include => company-B endif if $[{COMPANY} = C] include => company-C endif include => end-here The list of conditional variables, and of static includes is potentially large, so I do not want to create several separate sets of contexts with lots of repetition as it is likely to get out-of-control very quickly. Help? Steve
On Tue, Apr 22, 2008 at 09:55:37AM +0100, Steve Davies wrote:> Hi, > > Does anyone have a clever method of doing a conditional "include =>" > line in the dialplan? > > I want to include a bunch of standard contexts, but in the middle of > the bunch have one or more conditionally included, a bit like: > > [default] > include => start-here > include => then-here > if $[{COMPANY} = A] > include => company-A > endif > if $[{COMPANY} = B] > include => company-B > endif > if $[{COMPANY} = C] > include => company-C > endif > include => end-here > > > The list of conditional variables, and of static includes is > potentially large, so I do not want to create several separate sets of > contexts with lots of repetition as it is likely to get out-of-control > very quickly.A different approach: [company-base](!) ; common settings [company-A](company-base) ; specific for company A [company-B](company-base) ; specific for company B [company-C](company-base) ; specific for company C Keep in mind you can also use: [sub-template](!,base-template) And: [context](template1,template2) But one limitation is that you can only add: no way to remove line added by a template your context uses. -- Tzafrir Cohen icq#16849755 jabber:tzafrir.cohen at xorcom.com +972-50-7952406 mailto:tzafrir.cohen at xorcom.com http://www.xorcom.com iax:guest at local.xorcom.com/tzafrir
Steve Davies schrieb:> Does anyone have a clever method of doing a conditional "include =>" > line in the dialplan? > > I want to include a bunch of standard contexts, but in the middle of > the bunch have one or more conditionally included, a bit like: > > [default] > include => start-here > include => then-here > if $[{COMPANY} = A] > include => company-A > endif > if $[{COMPANY} = B] > include => company-B > endif > if $[{COMPANY} = C] > include => company-C > endif > include => end-here > > > The list of conditional variables, and of static includes is > potentially large, so I do not want to create several separate sets of > contexts with lots of repetition as it is likely to get out-of-control > very quickly.I suppose #ifdefs and a preprocessor like cpp is not what you're looking for? You didn't make clear at what stage you want these includes to be replaced / evaluated. I guess you want Asterisk to do it. Regards, Philipp Kempgen -- amooma GmbH - Bachstr. 126 - 56566 Neuwied - http://www.amooma.de Let's use IT to solve problems and not to create new ones. Asterisk? -> http://www.das-asterisk-buch.de Gesch?ftsf?hrer: Stefan Wintermeyer Handelsregister: Neuwied B 14998
2008/4/22 Tzafrir Cohen <tzafrir.cohen at xorcom.com>: [snip]> > A different approach: > > [company-base](!) > ; common settings > > [company-A](company-base) > ; specific for company A > > [company-B](company-base) > ; specific for company B > > [company-C](company-base) > ; specific for company C > > > Keep in mind you can also use: > > [sub-template](!,base-template) > > And: > > [context](template1,template2) > > But one limitation is that you can only add: no way to remove line added > by a template your context uses. >Wow! That took some finding, as it is little more than a footnote (page 115-116 of "Asterisk: The Future of Telephony") but is a fantastic feature... Given that I am using "include =>" statements, and the order of the includes is significant, do you know what order lines from templates are included? I will check the code, but can I assume that [template1](!) include => template1-patterns [template2](!) include => template2-patterns [context](template1,template2) include => context-patterns It the same as: [context] include => template1-patterns include => template2-patterns include => context-patterns and always in that order? Is this feature well used and well tested??? Thanks, Steve