template::adp_parse (public)
template::adp_parse __adp_stub __args
Defined in packages/acs-templating/tcl/parse-procs.tcl
Execute procedures to prepare data sources and then to output template. Assumes adp_level is set on entry. in general the public version template::adp_include should be used for generating strings from adp files.
- Parameters:
- __adp_stub (required)
- The root (without the file extension) of the absolute path to the template and associated code.
- __args (required)
- One list containing any number of key-value pairs passed to an included template from its container. All data sources may be passed by reference.
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- xowiki_test_cases
Source code: # declare any variables passed in to an include or master # TODO: call adp_set_vars instead. foreach {__key __value} $__args { # # Keys starting with "&" trigger call by reference. # if {[string range $__key 0 0] eq "&"} { if {"&" ne $__key } { set __name [string range $__key 1 end] } else { set __name $__value } upvar \#[adp_level] $__value $__name $__value:rowcount $__name:rowcount $__value:columns $__name:columns # upvar :rowcount and :columns just in case it is a multirow if { [info exists $__name:rowcount] } { for { set __i 0 } { $__i <= [set $__name:rowcount] } { incr __i } { upvar \#[adp_level] $__value:$__i $__name:$__i } } } else { # # Key does not start with "&" => normal arg (no reference). # set $__key $__value } } # # Set the stack frame at which the template is being parsed so # that other procedures can reference variables cleanly. # lappend ::template::parse_level [info level] # execute the code to prepare the data sources for a template set return_code [catch { set found_script_p [adp_prepare] # if we get here, adp_prepare ran without throwing an error. # initialize the ADP output set __adp_output "" set mime_type [get_mime_type] set template_extension [get_mime_template_extension $mime_type] # # Generate ADP output if a template exists (otherwise assume # plain Tcl page) # set templated_p 0 if { [ad_conn locale] ne "" && [file exists "$__adp_stub.[ad_conn locale].$template_extension"]} { # it's a localized version of a templated page set templated_p 1 append __adp_stub ".[ad_conn locale]" } elseif {[file exists "$__adp_stub.$template_extension"]} { # it's a regular templated page set templated_p 1 } if { [namespace which ::ds_page_fragment_cache_enabled_p] ne "" && [::ds_enabled_p] && [::ds_page_fragment_cache_enabled_p] && [::ds_collection_enabled_p] } { ns_cache lappend ds_page_bits [ad_conn request] $__adp_stub.$template_extension } if { $templated_p } { # # Ensure that template output procedure exists and is # up-to-date. By executing the reset, get result of # template output procedure into __adp_output, and # properties into __adp_properties # [template::adp_init $template_extension $__adp_stub] # JCD: Lets keep a copy of all the page fragments! WooHoo. if { [namespace which ::ds_page_fragment_cache_enabled_p] ne "" && [::ds_enabled_p] && [::ds_page_fragment_cache_enabled_p] && [::ds_collection_enabled_p] } { ns_cache set ds_page_bits "[ad_conn request]:$__adp_stub.$template_extension" $__adp_output } # call the master template if one has been defined if { [info exists __adp_master] } { # pass properties on to master template set __adp_output [template::adp_parse $__adp_master [concat [list __adp_slave $__adp_output] [array get __adp_properties]]] } } else { # # No template; found_script_p tells us if adp_prepare at # least found a script. # if { !$found_script_p } { # No template. Perhaps there is an HTML file. if { [file exists $__adp_stub.html] } { ns_log debug "getting output from ${__adp_stub}.html" set __adp_output [template::util::read_file "${__adp_stub}.html"] } elseif { [file exists $__adp_stub.htm] } { ns_log debug "getting output from ${__adp_stub}.htm" set __adp_output [template::util::read_file "${__adp_stub}.htm"] } else { error "No script or template found for page '$__adp_stub'" } } } return $__adp_output ; # empty in non-templated page } return_value] set s_errorInfo $::errorInfo set s_errorCode $::errorCode # Always pop off the parse_level no matter how we exit template::util::lpop ::template::parse_level switch -- $return_code { 0 - 2 { # CODE executed without a non-local exit -- return what it # evaluated to. return $return_value } 1 { # Error return -code error -errorinfo $s_errorInfo -errorcode $s_errorCode $return_value } default { if {$return_value eq "ADP_ABORT"} { # return without rendering any HTML if the code aborts return "" } else { return -code $return_code $return_value } } }XQL Not present: Generic, PostgreSQL, Oracle