ns_adp_registeradp registers an ADP string to be processed when the specified beginning and ending tags are used in an ADP. The tag is the beginning tag to look for, and the endtag is the ending tag to look for. The adpstring is the ADP text that will be parsed and executed when AOLserver encounters those tags when processing an ADP.
There are two ways to use ns_register_adptag, with and without the endcommand parameter:
If the endcommand parameter is specified, the procedure you specify with proc must be of the form:
proc myadpproc { string tagset }
|
The string is the string of characters between the beginning tag and the ending tag. The tagset is an ns_set of parameters that were specified with the beginning tag. The return value of the procedure will be sent to the browser in place of the string of text that was specified between the beginning and ending tags.
The string is not parsed, which means that you cannot include ADP tags in the string unless you execute ns_adp_parse on the string inside the procedure that processes the registered ADP tag.
If endcommand is not specified, then no closing tag is required. The procedure (proc) will be called every time the specified command is encountered. The procedure should take one parameter, an ns_set containing the parameters to the tag:
proc myadpproc { tagset }
|
Note: This function cannot be called after the server has started. It must be called in a Tcl script in a virtual server's Tcl directory so that it can be initialized at server startup time.
For example, suppose you want to register a tag that displays the enclosed text only if it is Christmas. You could register the tag as follows:
ns_register_adptag "christmas" "/christmas" xmas
proc xmas {string tagset} {
if {[ns_fmttime [ns_time] "%m/%d"] == "12/25"} then {
return $string
}
}
|
Then, in an ADP, you could use these tags:
<christmas>Merry Christmas to all, and to all a good night! </christmas> |
This example shows the use a registered tag without an endcommand. The tag is registered as follows:
ns_register_adptag hello helloproc
proc helloproc { tags } {
return "Hello, [ns_set get $tags name]."
}
|
In an ADP, you could then use this tag:
<hello name=Bob> |