Forum OpenACS Q&A: ad_return_template
Can someone enlighten me as to what/where/when to use
ad_return_template? As we port our site to OACS 4 it doesn't seem to
matter if we leave it in the .tcl file or take it out, and the doc
string for it in api-doc doesn't indicate what it really does...
I think originally the tcl file was sourced first. Now (maybe) the adp is. So you don't need the call to ad_return_template unless the template name is something other than the adp file root name.
The tcl file is still sourced first, but the search for a template is handled outside of the script itself.
Incidentally I think the default behaviour is inconvenient - if you create your adp templates under the www tree, along side your tcl scripts (the default place that is checked), then anyone can try to access the adp template directly by specifying an extension in the url. The templates will typically break because they usually require data from the tcl script. Perhaps by default it should check for an equivalent file under a templates dir instead of www?
Thanks Lee and Tom.
Lee, that behavior (still allowing access to the .adp or the .tcl when the template is what you really want to serve) has concerned me for a while too. Rather than default to a separate directory, wouldn't it be better if the RP for example did the following:
User requests http://somehost/page.adp rp checks to see if both page.tcl and page.adp are present if true, redirects to /page
Actually what happens for a recent version of OACS is that if both page.tcl and page.adp exist, then either page.tcl or page work the same. However, a request for page.adp returns file not found, and page.html, which does not exist returns a directory listing of the webserver pageroot: /web/server/www/. Sometimes other directories are returned.
What would be nice is if the ending didn't matter and was ignored in the usual case. In the case that page.xxx is requested and the adp and tcl file exist, it should process the pair as a template example. A redirect would be complicated, because it might be a post.
>Actually what happens for a recent version of OACS is that if both page.tcl and page.adp exist, then either page.tcl or page work the same.That's probably due to an ad_return_template at the end of tcl files which parses the adp template.
> In the case that page.xxx is requested and the adp and tcl file exist, it should process the pair as a template example.Looks like an option to me (maybe a parameter of the request processor would do it). Personally, I would prefer a 404 in that case which would enforce the abstract url system. Also, I prefer my pages accessible from only one url "page" instead of all three "page", "page.adp" and/or "page.tcl".
Is it in my nsd.tcl or in the request-processor?
(do I really have to roll up my sleeves and take a look myself )
About the 404 issue above: If someone wants to work on it I could provide info of what needs to be done. Otherwise, I'll do it over the weekend.