Forum OpenACS Q&A: Using different calls in .adp files

Collapse
Posted by Roberto Mello on
Hi all,

    In our community club site I use adp pages. I have created a set of
custom tags (with ad_register_styletag) that make writing a regular
static page faster. And I use the ad_header and ad_footer procs to
create top and bottom of the page respectively.

    I wanted to include a banner add right below our navigation bar. I
followed the docs and found the proc "adserver_get_ad_html" that takes
a group name as param and returns an ad with the proper HTML. The
problem is that ad_footer (which is parsed right after the above proc)
apparently also uses a connection from the pool 'main'.

        Most of the times it goes well, but sometimes the ad is not
generated because the thread is already owning a connection from main.
How do you solve that ? I mean, calling different procs within an adp
page. How do you control the pools and connections ?

    The other question is that only .html pages can get the "add
comment|add link" after being stuffed in the db. How can I accomplish
the same result in an adp page ? Can I just include a call in the page
? I have my static page module stuffing adp pages in the db as well as
.html.

    Thanks.

    Roberto Mello
Collapse
Posted by Ben Adida on
This will only happen if an error happens in a proc (or if the proc is badly written) and it doesn't release the handle it grabs. In general, procedures should grab from the subquery pool and release their handle before they exit.

As for adding a comment link and such, I believe there is a special ADP tag (or a tcl proc) that will automatically add these. Check the ad-html.tcl file.

Collapse
Posted by Roberto Mello on
I looked in tcl/ad-html.tcl and the comments say

# significantly enhanced in December 1999 to modularize the comment and link
# stuff so that .adp pages could use them as well (philg)

and found this proc that is called everytime a .html page is requested (included just the header because the proc is very big):

proc_doc ad_serve_html_page {ignore}

I then thought that by adding something like


  <%= [ad_footer]
      [ad_server_html_page] %>

I would get the links, but no. I put [ad_footer] because it stuff the footer plus /body and /html tags at the bottom, which ad_serve_html_pages look for to add the comments and links.

I tried several different things without success. On my logs AOLserver would complain that I was not passing a "ignore" parameter to the proc. What param should I pass (and why ?) ? Looking through the proc's code, it is not used anywhere.

In turn, If I do something like <% [ad_serve_html_page "0"] %> or [ad_server_html_page 0], the line is not parsed and is sent as text to the browser.

There's nothing in the module documentation that explains how to do it or if there's an ADP tag to accomplish this effect.

Any clues ?

Collapse
Posted by James Thornton on
I have a solution for including comments on ADP's and it also handles the abstract_url issue:
  1. set your nsd.tcl file to parse .html pages as ADP pages.
  2. modify ad_serve_html_page (in ad-html.tcl):
    	#set stream [open $full_filename r]
    	#set whole_page [read $stream]
    	#close $stream
    
    	set whole_page [ns_adp_parse -file $full_filename]
    
    Note: My ad_serve_html_page proc serves up a custom header and footer (no need for ad_header or ad_footer) -- titles and meta data are coded in the html/adp page.
  3. Save/convert your .adp files to .html -- here is a script that does this:
    #!/bin/sh
    # copies .adp files to .html
    for file in *.adp ; do
    	cp $file ${file%.adp}.html
    done
    
  4. sync your database

    I have this working at http://james.jamesthornton.com:8888 (let me know if it doesn't work -- I may have missed a step).

    If you already serve up a custom header and footer with ad_serve_html_page, then you will probably get doubles for adp pages that use ad_header and ad_footer.

    I had this working without modifying nsd.tcl to parse .html files as ADPs, but it did not work with abstract URLs (abstract URLs worked fine for HTML pages).