Forum OpenACS Q&A: Response to New template tag: include-optional

Collapse
Posted by Tom Jackson on

I have a new tag that I called read, but maybe source would be a better term. It works similarly to include, but you don't have to pass any variables to the include. One downside to this tag is that if you change the sourced file, the templating system doesn't pick up the change unless you touch the parent template adp. Here is the source which I put in acs-templating/tcl/tag-init.tcl:

template_tag read { params } {
 
   set source [ns_set iget $params src]
   if {![string match "absolute" [file pathtype $source]]} {
      set source [ns_normalizepath [ad_conn adp_root]/$source]
   }
   
   set chunk [template::util::read_file $source]
   template::adp_compile_chunk $chunk
}  

I also had to work around a 'bug' in the master tag, and maybe others that refer to filenames. You cannot specify an absolute file path in the original system. I used [ad_conn adp_root] to specify an absolute path. For the current system this should probably be pageroot?