Thanks for the tipoff Raul.
I tried the code snippet mentioned in https://openacs.org/forums/message-view?message%5fid=146238#149559 however the fundamental problem still stands that template::list::write_csv uses ns_return to return its output rather than returning a variable to the calling function. After looking at the code in list-procs.tcl it appears that template::list::write_output - if the format type is set to csv - simply calls template::list::write_csv and therefore I'm no better off than I was before.
Am I missing something fundamental here with ns_return ? My understanding/interpretation was that ns_return writes data straight out to the connection/template and as such can't be captured in a variable. Is this incorrect ?
By using the code in Jade & Randy's discussion I can get the browser to spit out an Excel-recognised CSV file, however as
set csv [template::list::write_output -name list_test]
doesn't actually prime the variable with data, the resulting CSV file is 0 bytes !
The solution I've put in place is to add a function to list-procs.tcl which is a direct copy of template::list::write_csv however I've substituted the return line
ns_return 200 text/plain $__output
with
set headers [ns_set new myheaders]
ns_set put $headers "Content-disposition" "attachment; filename=$file"
ns_respond -status 200 -type $mimetype -string $__output -headers $headers
and added some params so you can give it a filename and whatever mimetype you like (if Excel's not your cup of meat).
Anyway so that's where I got to, and it seems to work. Can anybody see any disastrous errors with what I've done ? Ideally I'd like to change it a little more so that there's not redundant code now living in write_csv and send_file_to_browser (my new function's name), however I didn't want to change the file too much.
Cheers,
Jason =)