--- title: "๐ŸŽจ Template Studio & Canonical AST Engine" description: "Designing universal auto-provisioning templates using the Canonical Abstract Syntax Tree (AST) and Jinja2 Transformer" --- > The **Template Studio** in Ring2All DMS enables VoIP engineers to construct hardware configuration templates that dynamically adapt to any user, extension count, or network topology without duplicating static files. --- ## ๐Ÿงฉ The Canonical AST Paradigm In traditional provisioning systems, each phone model requires a separate, hardcoded template file. If a phone supports 12 lines, engineers write 12 duplicate account blocks (`account.1.*`, `account.2.*`, ..., `account.12.*`). If a subscriber only has 1 extension, the phone boots with 11 empty accounts attempting registration or cluttering memory. **Ring2All DMS replaces this with a Canonical Abstract Syntax Tree (AST)**: 1. **Define Once**: Write a single universal template containing dynamic loop structures. 2. **Dynamic Generation**: When a phone boots, the Jinja2 synthesizer renders only the exact number of active accounts, line keys, and codecs assigned to that extension. 3. **Multi-Vendor Compilation**: The same logical AST structure can compile to Yealink `.cfg`, Grandstream `.xml`, Poly `.cfg`, or Snom `.htm`. ```mermaid flowchart TD AST["Canonical AST Template Definition
(Dynamic Loops & Macro Variables)"] Subscriber["Subscriber Extension Data
(Extensions: 101, 102 | Server: 10.9.0.10 | Codecs: Opus, G.722)"] Synthesizer["Jinja2 Synthesizer & AST Compiler"] AST --> Synthesizer Subscriber --> Synthesizer Synthesizer --> Out1["Yealink Output (y000000000000.cfg)
account.1.enable = 1
account.2.enable = 1"] Synthesizer --> Out2["Grandstream Output (cfg{mac}.xml)
<P271>1</P271>
<P47>10.9.0.10</P47>"] Synthesizer --> Out3["Poly Output ({mac}-reg.cfg)
reg.1.address='101'
reg.2.address='102'"] ``` ![Template Studio Workbench](/screenshots/dms/template-studio/template-studio.png) ### Template Studio Workspaces & Tabs Template Studio organizes hardware configuration into three synchronized functional tabs: #### 1. Models & Template Catalog Browse vendor-specific template files and certified base definitions across all manufacturers. ![Models & Template Catalog Tab](/screenshots/dms/template-studio/template-studio-models-template-catalog.png) #### 2. Studio Compiler & Real-Time Synthesizer Side-by-side IDE featuring live parameter interpolation, AST syntax checking, and multi-tenant loop expansions. ![Studio Compiler Tab](/screenshots/dms/template-studio/template-studio-studio-compiler.png) #### 3. Canonical AST Macro Reference Interactive dictionary of all available variables, loop definitions, codec structures, and vendor code mappings. ![AST Macro Reference Tab](/screenshots/dms/template-studio/template-studio-ast-macro-reference.png) --- ## ๐Ÿ” Dynamic Account Loops Account configuration is wrapped inside dynamic loop directives that expand according to the subscriber's assigned SIP credentials: ```jinja2 #!version:1.0.0.1 ## ============================================================================== ## Dynamic SIP Account Provisioning ## ============================================================================== {{LOOP_ACCOUNTS_START}} account.{{ACCOUNT_INDEX}}.enable = {{ACCOUNT_ENABLED}} account.{{ACCOUNT_INDEX}}.label = {{ACCOUNT_LABEL}} account.{{ACCOUNT_INDEX}}.display_name = {{ACCOUNT_DISPLAY_NAME}} account.{{ACCOUNT_INDEX}}.auth_name = {{AUTH_USERNAME}} account.{{ACCOUNT_INDEX}}.user_name = {{EXTENSION_NUMBER}} account.{{ACCOUNT_INDEX}}.password = {{SIP_PASSWORD}} account.{{ACCOUNT_INDEX}}.sip_server.1.address = {{SIP_SERVER_IP}} account.{{ACCOUNT_INDEX}}.sip_server.1.port = {{SIP_SERVER_PORT}} account.{{ACCOUNT_INDEX}}.sip_server.1.transport_type = {{SIP_TRANSPORT}} account.{{ACCOUNT_INDEX}}.codec.opus.enable = 1 account.{{ACCOUNT_INDEX}}.codec.opus.priority = 1 account.{{ACCOUNT_INDEX}}.codec.g722.enable = 1 account.{{ACCOUNT_INDEX}}.codec.g722.priority = 2 account.{{ACCOUNT_INDEX}}.codec.pcmu.enable = 1 account.{{ACCOUNT_INDEX}}.codec.pcmu.priority = 3 {{LOOP_ACCOUNTS_END}} ``` ### Standard Loop Variables: | Macro Variable | Description | Resolved Example | | :--- | :--- | :--- | | `{{ACCOUNT_INDEX}}` | Sequential index of the account on the phone | `1`, `2`, `3` | | `{{ACCOUNT_ENABLED}}` | Binary indicator whether line is active | `1` or `0` | | `{{ACCOUNT_LABEL}}` | Friendly text displayed on phone LCD line key | `Sales (101)` | | `{{EXTENSION_NUMBER}}` | SIP username / extension identifier | `101` | | `{{AUTH_USERNAME}}` | Digest authentication username | `ext_101_tenant4` | | `{{SIP_PASSWORD}}` | Secure registration secret | `v9$Kx#7mQ9p!zL` | | `{{SIP_SERVER_IP}}` | Outbound proxy or PBX domain | `pbx.carrier.com` | | `{{SIP_SERVER_PORT}}` | Signaling port | `5060` (UDP/TCP) or `5061` (TLS) | | `{{SIP_TRANSPORT}}` | Transport protocol indicator | `0` (UDP), `1` (TCP), `2` (TLS) | --- ## ๐ŸŽ›๏ธ Programmable Line Keys & DSS Loops For executive phones and attendant consoles with dozens of line keys, Template Studio provides dedicated loops for Busy Lamp Fields (BLF), Speed Dials, and Call Parks: ```jinja2 ## ============================================================================== ## Programmable DSS Line Keys ## ============================================================================== {{LOOP_LINEKEYS_START}} linekey.{{KEY_INDEX}}.type = {{KEY_TYPE_CODE}} linekey.{{KEY_INDEX}}.line = {{KEY_ACCOUNT_INDEX}} linekey.{{KEY_INDEX}}.value = {{KEY_TARGET_VALUE}} linekey.{{KEY_INDEX}}.label = {{KEY_DISPLAY_LABEL}} linekey.{{KEY_INDEX}}.extension = {{KEY_PICKUP_CODE}} {{LOOP_LINEKEYS_END}} ``` Supported Key Types automatically translate into the vendor's internal numeric key type code: * **Line Key**: Registers standard call appearance for the account. * **BLF (Busy Lamp Field)**: Real-time subscription to extension presence via SIP NOTIFY. * **Speed Dial**: One-touch dialer for external PSTN numbers or internal short codes. * **Call Park**: Monitors Valet Parking lots with one-touch orbit retrieval. * **Intercom / Paging**: Initiates two-way direct intercom or one-way public announcement. --- ## ๐Ÿงช Live Simulation & Syntax Preview Template Studio includes a real-time side-by-side simulator: 1. **Template Editor (Left Panel)**: Code editor with syntax highlighting, auto-completion of macro variables, and linting. 2. **Simulation Variables (Center Panel)**: Mock subscriber environment where engineers configure test parameters (e.g., 3 accounts, TLS transport, 8 BLF keys). 3. **Generated Configuration Output (Right Panel)**: Live output showing the exact character-for-character file that the phone will receive upon downloading over HTTPS. --- ## ๐ŸŽฏ User Roles & Key Capabilities | User Role | Operations in Template Studio | | :--- | :--- | | **VoIP Hardware Architect** | Authors canonical templates, tests account loop expansions, and verifies manufacturer compatibility. | | **PBX Administrator** | Customizes corporate feature parameters (screensavers, corporate LDAP address books, NTP time zones). | | **Support Tech** | Simulates customer configuration files during troubleshooting to verify codec priority and SIP port assignments. |