Index: openacs-4/packages/acs-templating/tcl/parse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/parse-procs.tcl,v diff -u -r1.26.2.8 -r1.26.2.9 --- openacs-4/packages/acs-templating/tcl/parse-procs.tcl 21 Nov 2005 17:28:14 -0000 1.26.2.8 +++ openacs-4/packages/acs-templating/tcl/parse-procs.tcl 21 Nov 2005 17:48:26 -0000 1.26.2.9 @@ -13,6 +13,52 @@ namespace eval template {} + +ad_proc -public template::adp_include { + {-uplevel 1} + src + varlist +} { + return a the output of a tcl/adp pair as a string. adp_level is + set to the calling procedure so that pass by reference works. + and example of using this is in the search indexer for various content + types: +
+    bookshelf::book::get -book_id $book_id -array bookdata
+    set body [template::adp_include /packages/bookshelf/lib/one-book \ 
+                  [list &book "bookdata" base $base style feed]]
+  
+ + The [list &book "bookdata" ...] tells adp_include to pass the book array by reference to the adp include, where it is + refered to via @book.field@. + + @param uplevel how far up the stack should the adp_level be set to + (default is the calling procedures level) + @param src should be the path to the tcl/adp pair relative to the server root, as + with the src attribute to the include tag. + @param varlist a list of {key value key value ... } varlist can also be &var foo + for things passed by reference (arrays and multirows) + + @return the string generated by the tcl/adp pair. + + @author Jeff Davis davis@xarg.net + @creation-date 2004-06-02 + + @see template::adp_parse +} { + # set the stack frame at which the template is being parsed so that + # other procedures can reference variables cleanly + variable parse_level + lappend parse_level [expr [info level] - $uplevel] + + set __adp_out [template::adp_parse [template::util::url_to_file $src] $varlist] + + # pop off parse level + template::util::lpop parse_level + + return $__adp_out +} + ad_proc -private template::adp_parse { __adp_stub __args } { Execute procedures to prepare data sources and then to output template. @@ -371,10 +417,11 @@ # TODO: ad_quotehtml # TODO: lang::util::localize - regsub -all {[\]\[\{\}\"]\\$} $substitution {\\&} substitution +# regsub -all {[\]\[\{\}\"]\\$} $substitution {\\&} substitution if { [regexp {^%([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)%$} $substitution match arr key] } { # the array key name is substitured by the tcl parser s - regsub -all {[\]\[\{\}\"]\\$} $key {\\&} key +# regsub -all {[\]\[\{\}\"]\\$} $key {\\&} key + set command "set ${arr}(${key})" set substitution [uplevel $command] } if { [regexp {^%([a-zA-Z0-9_:]+)%$} $substitution match var] } {