NaviServer Programmable Web Server

ns_adp_include(n)

NaviServer Built-in Commands – 5.1.0


[ Main Table Of Contents | Table Of Contents | Keyword Index ]

Name

ns_adp_include - Include and execute an ADP file

Table Of Contents

Synopsis

Description

This command includes an ADP file in some other ADP file. ADP files can be nested by including each other up to the maximum of 256 levels deep.

This command includes and executes an ADP file within the current ADP. The output produced by the included file (both static text and script output) is appended to the current output buffer.

ADP files can be nested by including each other up to a maximum depth (currently 256 levels).

This command is only available while processing an ADP file. To parse an ADP outside of an ADP context, use ns_adp_parse.

COMMANDS

ns_adp_include ?-cache time? ?-nocache? ?-tcl? ?--? filename ?arg ...?

Include and execute the ADP file specified by filename. The file name may be absolute or relative to the current ADP working directory (i.e., the directory of the including file).

The included ADP is executed in a new call frame with its own local variables, similar to a Tcl procedure.

Additional arguments (arg ...) are passed to the included ADP and can be accessed via ns_adp_argc, ns_adp_argv, and ns_adp_bind_args.

The option -cache specifies a time (in seconds) for caching the generated output. When caching is enabled, the complete output of the included ADP (including nested includes) is stored and reused for subsequent requests.

The option -nocache disables caching for this include and any content generated within it, even if surrounding includes use caching.

The options -cache and -nocache can be combined to optimize performance for ADPs that mix static/shared content with dynamic or personalized content.

The option -tcl treats the specified filename as a Tcl script and wraps it on the fly as an ADP page.

EXAMPLES

 ###
 ### Example: ADP file "a.adp" includes ADP file "b.adp"
 ###
 
 # In a.adp:
 begin of a.adp<br>
 <% ns_adp_include b.adp %>
 end of a.adp<br>
 
 # In b.adp:
 begin of b.adp<br>
 ...<br>
 <% ns_adp_puts "Hello, world!" %><br>
 ...<br>    
 end of b.adp<br>

Passing arguments to an included ADP:

 # In a.adp:
 begin of a.adp<br>
 <% ns_adp_include b.adp 1 2 3%>
 end of a.adp<br>
 
 # In b.adp:
 begin of b.adp<br>
 ...<br>
 <% ns_adp_puts "Arguments: [ns_adp_argv]" %><br>
 <%
   ns_adp_bind_args x y z
   ns_adp_puts "x=$x y=$y z=$z"      ;# => {x=1 y=2 z=3}
 %>
 ...<br>
 end of b.adp<br>

See Also

ns_adp, ns_adp_abort, ns_adp_append, ns_adp_argc, ns_adp_argv, ns_adp_bind_args, ns_adp_break, ns_adp_debug, ns_adp_dir, ns_adp_dump, ns_adp_exception, ns_adp_mimetype, ns_adp_parse, ns_adp_puts, ns_adp_register, ns_adp_return, ns_adp_stats, ns_adp_tell, ns_adp_trunc, ns_time

Keywords

ADP, server built-in