Difference between revisions of "Ns adp registerscript"

From AOLserver Wiki
Jump to navigation Jump to search
(Copied from old API documentation)
 
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
'''NAME'''
 
'''NAME'''
  
: ns_register_adptag - Register an XML-like tag for use within an ADP.
+
: ns_adp_registerscript - Register an XML-like tag for use within an ADP.
  
 
'''SYNOPSIS'''
 
'''SYNOPSIS'''
  
: '''ns_register_adptag''' command ''?endcommand?'' proc
+
: '''ns_adp_registerscript''' tag ''?endtag?'' proc
 +
: '''ns_register_adptag''' tag ''?endtag?'' proc
  
 
'''DESCRIPTION'''
 
'''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 AOLserver encounters those tags when processing an ADP.
+
: '''ns_adp_registerscript''' registers a procedure to be called 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 proc is the procedure that will be called when AOLserver encounters those tags when processing an ADP.
  
: Try not to confuse '''ns_register_adptag''' with [[ns_adp_registertag]]. This one registers a Tcl proc that is run by the tag. The other one registers an ADP script that is run by the tag.
+
: Try not to confuse '''ns_adp_registerscript''' with [[ns_adp_registeradp]]. This one registers a Tcl script/proc that is run by the tag. The other one registers an ADP script that is run by the tag.  Also [[ns_adp_registerproc]] is similar to this command but with that command, the proc is invoked with individual attribute arguments instead of a single ns_set.
  
: There are two ways to use '''ns_register_adptag''', with and without the ''endcommand'' parameter:
+
: There are two ways to use '''ns_adp_registerscript''', with and without the ''endtag'' parameter:
  
* If the endcommand parameter is specified, the procedure you specify with proc must be of the form:
+
* If the endtag parameter is specified, the procedure you specify with proc must be of the form:
  
 
     proc myadpproc { string tagset }
 
     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 the string of characters between the beginning tag and the ending tag. The tagset is an [[ns_set]] of attributes 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.
+
: In AOLserver 4.0 and older, the string is not parsed, which means that you could not include ADP tags in the string unless you execute [[ns_adp_parse]] on the string inside the procedure that processes the registered ADP tag.  In AOLserver 4.5, <% %> ADP tags in the string do get parsed.
  
* 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:
+
* If ''endtag'' 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 attributes to the tag:
  
 
     proc myadpproc { tagset }
 
     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.
+
: Note that the reason this command is called ns_adp_registerscript is technically you can register any tcl script to be invoked to which the one or two parameters would be appended and the whole thing would be wrapped in square brackets and evaluated. It doesn't really have to be a single procedure name but it does have to start with a procedure/command name.
  
 
'''EXAMPLE'''
 
'''EXAMPLE'''
Line 37: Line 38:
 
: Suppose you want to register a tag that displays the enclosed text only if it is Christmas. You could register the tag as follows:
 
: 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
+
     ns_adp_registerscript "christmas" "/christmas" xmas
  
 
     # Note: We are registering a Tcl proc.
 
     # Note: We are registering a Tcl proc.
Line 50: Line 51:
 
     <christmas>Merry Christmas to all, and to all a good night!</christmas>
 
     <christmas>Merry Christmas to all, and to all a good night!</christmas>
  
: In another example we show how to use a registered tag without an ''endcommand''. The tag is registered as follows:
+
: In another example we show how to use a registered tag without an ''endtag''. The tag is registered as follows:
  
     ns_register_adptag hello helloproc
+
     ns_adp_registerscript hello helloproc
  
 
     # Note: We are registering a Tcl proc.
 
     # Note: We are registering a Tcl proc.
Line 67: Line 68:
 
'''SEE ALSO'''
 
'''SEE ALSO'''
  
: [[ns_adp_registertag]], [[ns_adp_parse]]
+
: [[ns_adp_registerproc]], [[ns_adp_parse]]
 +
 
 +
[[Category:Documentation]] [[Category:Core Tcl API]]

Latest revision as of 08:19, 14 October 2009

Man page: http://aolserver.com/docs/devel/tcl/api/adp.html#ns_register_adptag


NAME

ns_adp_registerscript - Register an XML-like tag for use within an ADP.

SYNOPSIS

ns_adp_registerscript tag ?endtag? proc
ns_register_adptag tag ?endtag? proc

DESCRIPTION

ns_adp_registerscript registers a procedure to be called 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 proc is the procedure that will be called when AOLserver encounters those tags when processing an ADP.
Try not to confuse ns_adp_registerscript with ns_adp_registeradp. This one registers a Tcl script/proc that is run by the tag. The other one registers an ADP script that is run by the tag. Also ns_adp_registerproc is similar to this command but with that command, the proc is invoked with individual attribute arguments instead of a single ns_set.
There are two ways to use ns_adp_registerscript, with and without the endtag parameter:
  • If the endtag 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 attributes 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.
In AOLserver 4.0 and older, the string is not parsed, which means that you could not include ADP tags in the string unless you execute ns_adp_parse on the string inside the procedure that processes the registered ADP tag. In AOLserver 4.5, <% %> ADP tags in the string do get parsed.
  • If endtag 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 attributes to the tag:
   proc myadpproc { tagset }
Note that the reason this command is called ns_adp_registerscript is technically you can register any tcl script to be invoked to which the one or two parameters would be appended and the whole thing would be wrapped in square brackets and evaluated. It doesn't really have to be a single procedure name but it does have to start with a procedure/command name.

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_adp_registerscript "christmas" "/christmas" xmas
   # Note: We are registering a Tcl proc.
   proc xmas {string tagset} {
       if {[ns_fmttime [ns_time] "%m/%d"] == "12/25"}  then {
           return $string
       }
   }
Then, in an ADP, you use these tags:
   <christmas>Merry Christmas to all, and to all a good night!</christmas>
In another example we show how to use a registered tag without an endtag. The tag is registered as follows:
   ns_adp_registerscript hello helloproc
   # Note: We are registering a Tcl proc.
   proc helloproc { tags } {
       return "Hello, [ns_set get $tags name]."
   }
In an ADP, you use this tag:
   <hello name=Bob>
This can be extended to provide XML-like template pages for content.

SEE ALSO

ns_adp_registerproc, ns_adp_parse