Forum OpenACS Q&A: ad_return_template

Collapse
Posted by C. R. Oldham on
Greetings,

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...

Collapse
Posted by Tom Jackson on

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.

Collapse
Posted by Lee Denison on
Originally adp templates were only parsed when ad_return_template was explicitly called at the end of the tcl script.  In more recent versions of OACS the handling of adp templates is implicit (ie if a correspoding adp file exists for the tcl file being evaluated, it gets evaluated immediately afterwards).  The ad_return_template function still exists for backwards compatibility and to allow you to specify a template other than the default.  With no arguments, ad_return_template is a noop.

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?

Collapse
Posted by C. R. Oldham on

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
Collapse
Posted by Neophytos Demetriou on
I have a workaround for the problem with the adp pages being viewable that won't allow viewing "page.adp" and/or "page.tcl". Instead, it will only accept "page". Same holds for ".html" pages. If this is what people want I can write a clean patch and apply it. So what do you think?
Collapse
Posted by Don Baccus on
Someone would need to spend a few minutes with grep to make sure none of the existing code says ".tcl" or ".adp".  My first thought is that the idea's fine for .adp/.tcl files but there's no need to do so for .html file.  .html files are standalone files so shouldn't crash in the way that .adp files can.
Collapse
Posted by Tom Jackson on

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.

Collapse
Posted by Neophytos Demetriou on
As Don says we would have to cleanup the code for such a change but afaics there not many places where ".tcl" or ".adp" extensions are used. There are some though, for example, in the site-map we have "unmounted.tcl" instead of "unmounted"...
>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".
Collapse
Posted by David Walker on
I also like the 404 idea.  I think it simplifies the request processor's already
complex job.
Collapse
Posted by Lars Pind on
Btw, did anyone bother to figure out why it is that you get a directory listing instead of a 404 just about every time, these days?

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 😃)

Collapse
Posted by Steve Woodcock on

Lars, there are two patches for this in the SDM, #119 and #121, both of which should be applied. Check this thread for the discussion.

Collapse
Posted by Lee Denison on
I also prefer the 404 for requests with the extensions - keeping the RP simple should be a priority.
Collapse
Posted by Neophytos Demetriou on
I have just applied patches #119 and  #121. I did some testing and they look ok. Could someone test and confirm, Steve :)

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.

Collapse
Posted by Neophytos Demetriou on
About the abstract urls issue (above): I have written a clean solution and I have been doing a wipe out of the .tcl and .adp extensions from links within the files all week long. There are still a lot more to clean up but I hope it will be ready before our official release. The solution is going to provide a parameter for the request processor so those who want to make there urls accesible with these extensions will be able to do it.