Forum OpenACS Development: Access to templating system from non-connection threads

I'm working on a small email helper that allows you to use the acs templating system to format the email. Unfortunately it doesn't work out of the box. One of the mime procedures uses ns_conn, which barfs if the thread isn't connected. I made a small change to this proc, and it works great, but I wonder if there is a more complete solution to this issue. The proc is in packages/acs-templating/tcl/mime-procs.tcl:

ad_proc -public template::get_mime_type {} {
  set mime_type ""
  if {[ns_conn isconnected]} {
    set mime_type [ns_set iget [ns_conn outputheaders] "content-type"]
  }
  if { [empty_string_p $mime_type] } {
    set mime_type "text/html"
  }

  return $mime_type
}

I haven't really investigated why the output headers were consulted for this, seems like there might be another place to find this information.

I recently created a scheduled proc that is also intended to send out email formatted with the help of acs-templating.

After hitting this same brick wall, I decided it was easier to use ns_httpget to get the formatted html.

I may try your code for my work too.

(caveat: this was done in ACS, not Open ACS. It should work anyway.)

I also just used the same trick, that is ns_conn isconnected, to let me use the same page from either the website or a scheduled proc. At the top of my tcl page I use:

if {[ns_conn isconnected]} {
  set order_id [ns_queryget order_id]
}

You could also probably surround ad_page_contract as well. This makes it a lot easier to test template changes without waiting for the schedule proc to fire.

Another possiblity would be to do the whole job outside of AOLserver and use nstcl, which, as of version 1.0, now implements a compatible set of templating commands (pretty much everything that's not form-processing specific).