Forum OpenACS Q&A: TCL Q--> How do Include a file?

Collapse
Posted by Nathan Reeves on
Okay,  this verges on the stupid I'm sure,  but I'm trying to work
out how to include a html file at the top of all my pages.  I want to
include a standard header on all pages and I've created a .htm file
with all the html I want (including Javascript).  I've tried to
create a proc which just returns the text but it barfs on the
javascript because the tcl interpreter thinks its parsing tcl.  How
do I prevent the parser from parsing that one peice of text?

Thanks in advance

Collapse
Posted by Michael A. Cleverly on
When you say that your Tcl proc "barfs on the javascript because the tcl interpreter thinks it is parsing tcl" it sounds like you've got a chunk of javascript like this:
proc my_header_text {} {
    return " ... java script stuff ... "
}
In which case any $ or braces are going to be interpreted by Tcl. What you want instead is to wrap your chunk of javascript in curl braces like:
proc my_header_text {} {
    return { ... javascript stuff here ... }
}
Curly-braces defer execution in Tcl. If you need to dynamically generate javascript code from Tcl (based on Tcl variables, details about the connection, etc.) then you need to escape all the $ and braces with backslashes.
Collapse
Posted by Nathan Reeves on
Thankyou.  Solved my problem.