Forum OpenACS Q&A: returning content from an include without a .adp

is it possible to return content through the templating system without using a .adp file? I'm cleaning/refactoring an old app and have hit a couple of spots where it'd be great to be able to return content from an <include>ed .tcl fragment without needing an associated .adp file.

there are several spots where html is being hand-generated by TCL code. I've split these out to page fragments that can be included, but the .tcl file is the only bit that actually does anything - it builds up content in a html_output variable and then the .adp contains nothing but

@html_output@

several other spots have content that may or may not be included in an output page and is currently wrapped in templating system conditionals which I've broken out for reuse elsewhere as includable page fragments. these contain both .tcl and .adp files where the entire content of the .adp is wrapped in a templating conditional. I'd like to be able to remove this cruft from the .adp and put something like this at the top of the .tcl file to make it skip the .adp and just return an empty string if there is nothing relevant to show -

if {![asset_has_related_items $asset_id]} {
  # what do I use for these calls?
  adp_return_content ""
  adp_abort
}

template::adp_puts appears to be what I want for returning content from the .tcl file, except it only seems to work in escaped TCL code inside a .adp page. I've not found anything that works for stopping the evaluation of an included fragment that doesn't also kill the including page as well...

is this sort of fooling with the template system supported?

Collapse
Posted by russ m on
d'oh... by "@html_output@" I actually mean "@html_output;noquote@"... and in case it matters this is currently on OpenACS 5.3.2 though coming up to a current release is something I'm planning on doing sometime soon...
Collapse
Posted by Dave Bauer on
Collapse
Posted by russ m on
is that not for executing a tcl/adp pair from within tcl code? that's not what I'm trying to do... in the template for some page, say I have

&lt;include src="../lib/related-items" asset_id="@asset_id@"&gt;

and then in related-items.tcl I want to be able to do something like

set related_items [asset_related_items $asset_id]
if { [llength $related_items] == 0 } {
  write_some_content_to_the_templated_output "&lt;p&gt;no related items&lt;/p&gt;"
  return_here_and_dont_parse_the_adp_file
}
... more stuff ...

so I don't need to have the entire .adp wrapped in a big conditional that just says whether to display anything or not...

Collapse
Posted by Dave Bauer on
I guess I don't understand the question.

I don't think you can do what you want to do.

What you really probably want are Tcl procedures that return the correct results. Then you can call them instead of including a Tcl file without an ADP.

Another option is to use the ADP as intended and instead of having @html_output;noqoute@ you'd put the HTML tags and static content in the ADP with the appropriate Tcl variables to fill in the dynamic parts of the content.