NaviServer Programmable Web Server

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

ns_adp_parse(n) 5.1.0 naviserver "NaviServer Built-in Commands"

Name

ns_adp_parse - Parse an ADP file or string and return its output

Table Of Contents

Synopsis

Description

This command processes the specified ADP file or string and returns the result as a string. Processing a second ADP from inside an ADP is normally best done with ns_adp_include, since that command resolves relative pathnames passed to it. Also note that ns_adp_parse ignores directives to turn on streaming. Tcl commands embedded in ADP are evaluated with Tcl_Eval.

Although the <% ... %> syntax is allowed in the string, if you construct such a string inside an ADP script block, take care not to prematurely terminate the enclosing script block.

The optional -tagset argument selects the registered ADP tag set used while parsing this input. Tag sets are managed with ns_adp_tagset and allow different registered-tag vocabularies to coexist in the same server.

COMMANDS

ns_adp_parse ?-cwd value? ?-file? ?-safe? ?-string? ?-tagset name? ?-tcl? ?--? arg ...

OPTIONS

-cwd value

Sets the current working directory for this ADP parse operation. This affects relative pathname resolution during the parse.

-file

Treats the first argument as the name of an ADP file to parse. This is similar to ns_adp_include, except that the result is returned by ns_adp_parse instead of being appended directly to the current ADP output stream.

-safe

Sets the ADP safe flag for this parse operation.

-string

Treats the first argument as an ADP string. This option is provided for backward compatibility; string mode is the default.

-tagset name

Selects the ADP tag set used while parsing this input.

If -tagset is omitted, the current effective tag set is inherited. This means that nested parses normally use the same tag set as their caller.

If -tagset default is specified, the parse operation uses the built-in server-wide default ADP tag table for this operation only.

If -tagset name is specified with a named tag set, that tag set is used for this parse operation only. After the parse completes, the previous effective tag set is restored.

The effective tag set is part of the identity of parsed ADP code. When ADP files are cached, the same file parsed under different named tag sets is cached separately.

-tcl

Treats the first argument as Tcl code or, together with -file, as a Tcl file.

Additional arguments can be provided and are passed to the ADP evaluation. The arguments can be accessed within the ADP using ns_adp_argc, ns_adp_argv, and ns_adp_bind_args.

If this call is a nested ADP evaluation, an error is thrown if the depth exceeds 256, the maximum number of nested ADP evaluations.

EXAMPLES

Parse an ADP string:

 % ns_adp_parse {2 + 2 = <%= [expr 2 + 2] %> !!!}
 2 + 2 = 4 !!!

Parse an ADP file and return the generated output:

 % ns_adp_parse -file foo.adp

Parse using a named ADP tag set:

 % ns_adp_tagset create -fallback default transformed-adp
 % ns_adp_parse -tagset transformed-adp -string {
     Before <mytag>content</mytag> after
   }

Force the built-in default tag table for a nested parse:

 % ns_adp_parse -tagset default -string {
     <legacytag>content</legacytag>
   }

For more background about ADP, see ADP Overview.

See Also

ns_adp_argc, ns_adp_argv, ns_adp_bind_args, ns_adp_include, ns_adp_register, ns_adp_tagset, ns_register

Keywords

ADP, server built-in, tagset