NaviServer - programmable web server


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

ns_register_adptag(n) 4.99.3 naviserver "NaviServer Built-in Commands"

Name

ns_register_adptag - Register a tag for use within an ADP

Table Of Contents

Synopsis

Description

ns_register_adptag registers a procedure to be called when the specified beginning and ending tags are used in an ADP. The command is the beginning tag to look for, and the endcommand is the ending tag to look for. The proc is the procedure that will be called when Naviserver encounters those tags when processing an ADP.

There are two ways to use ns_register_adptag, with and without the endcommand parameter:

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.

COMMANDS

ns_register_adptag command ?endcommand? proc

EXAMPLES

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" } {
    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>

See Also

nsd

Keywords

NaviServer