Forum OpenACS Q&A: returning a different adp template from within an <include>

Is there any way to have the .tcl component of an <include>ed page fragment return a non-default .adp template and stop running?

I'm refactoring an existing app and want to move a bunch of nasty presentation logic into template chunks that can be <include>ed... One of these needs to check if the user is logged in, and if so do some DB stuff and return it in a templated chunk, but if not return a much simpler "please log in" page fragment. The current .adp is liberally sprinkled with <if @user_id@ eq 0>, but what I want to do is change the .tcl to be something like

set user_id [ad_conn user_id]
if { $user_id == 0 } {
  ad_return_template "simplified-output.adp"
  ad_script_abort
}
... do stuff for logged in folks ...
which (unsurprisingly) doesn't do what I want... Is there a way of returning a non-default .adp from an include and terminating further processing in the included tcl chunk?
I do it all the time... most of the time to create a print view verses as web view.

Try with simplified-output instead of simplified-output.adp

Collapse
Posted by russ m on
ah, thanks for that (it's what I tried first, but was using paths relative to the fragment .tcl file rather than the calling page). But processing still continues in the tcl file once the alternate template is returned though - do you know any &lt;include&gt;-compatible analogue to ad_script_abort?

And while I'm on the topic of the templating system, I also have a couple of cases where large chunks of display HTML are generated purely in tcl... these are now living in &lt;include&gt;ed page fragments, where the .adp is nothing but

@fragment_html;noquote@

Is there a way of getting fragment output directly from a .tcl file into the result page without having to tweak templating-private data structures?

You'll need to rearrange your Tcl logic.

When the template is compiled it generates one long tcl script with the compiled code for each include in the right place in the script. So if you call ad_script_abort in an include, it stop processing for the entire request.