Forum OpenACS Q&A: General Comments on adp pages

Collapse
Posted by tammy m on
Hi

I'm new to OpenACS and just got up and running with 4.6.

I want to add General Comments links and comments to my pages but I have moved all my static html pages to adp pages to take advantage of the templating system.

What is the best way to go about adding comments + links from General Comments to my pages? Do I have to revert to html pages? If so, can I use some form of master templates to wrap html pages at least?

Thanks for any insight.

Collapse
Posted by Ola Hansson on
tammy,

Install and mount static-pages and general-comments and put your original (html) pages in some dir(s) you create (mkdir) under the page root (www) dir. Then restart the server. Now, scan your pages from the static-pages admin pages and possibly change some params for that package in the sitemap.

Voila! You should be able to comment on your pages.

/Ola

Collapse
Posted by Ola Hansson on
You can toggle on/off if you want to use templating or not via one of static-pages' parameters. If you activate templating you should look at www/default-master.* and maybe also /packages/static-pages/www/templates/static.adp.

HTH.

Collapse
Posted by tammy m on
Thanks Ola.

Can I add comments/links to my adp pages too? Or do my pages have to be static html to be able to use comments/links?

I noticed this posting that James Thornton had come up with a way to add comments/links to adp pages. But this posting is older and I am wondering if there is a general consensus on the "best" way to do this now. Or even if this functionality is more built in to OACS today.

Thanks again.

Collapse
Posted by Joel Aufrecht on
Here's what I stole from some other package - I offer it up as a straw man for the "right way" to do comments for things that aren't static pages.

You can track comments for any ACS Object. Let's assume that your package is notes, and you've created it as per the tutorial so that each note is also an acs object. (That is, each entry in the notes table has a corresponding entry in acs_objects, and this is enforced with a foreign key and implemented by having a notes__new stored procedure which calls acs_object__new.) Now you have an adp/tcl pair that presents a note.

First, you need to generate a url for adding comments.

set comment_add_url "[general_comments_package_url]comment-add?[export_vars {
 { object_id $note_id } 
 { object_name $title } 
 { return_url "[ad_conn url]?[ad_conn query]"} 
}]"

This calls a global, public tcl function that the general_comments package registered, to get its url. You then embed in that url the id of the note and its title, and set the return_url to the current url so that the user can return after adding a comment.

Now, you need to create html that shows any existing comments. You do this by calling another general_comments function:


set comments_html [general_comments_get_comments -print_content_p 1 $note_id]

First, you pass in a parameter that that says to actually show the contents of the comments, instead of just the fact that there are comments. Then you pass the note id, which is also the acs_object id.

Now that you've set up these two variables, you need to put them in your adp page:


bla blah blah
<a href="@comment_add_url@">Add a comment</a>
<p>@comments_html@

If you want to learn more about these functions, you can go to /api-doc on your instance and look them up or browse to them, if you have general-comments installed.

Collapse
Posted by tammy m on
Ok so maybe I am asking several questions here. One is a basic issue of best practice and the others are more technical implementation issues...

I found this thread discussing using adp versus html for magnet/basic content of a site in general. i.e. What is the preferred format for pages that are mostly static? I assume that lots of folks using OACS are using General Comments. Do y'all keep all your content in HTML pages instead of ADPs?

Benefits of HTML are that using Static Pages, allows you to have General Comments/Links, use the Content Repository and get FullTextSearch via the SiteWideSearch package. (as I understand this so far)

Benefits of ADP are that I can use default-master templates and associated TCL files to access datasources, etc and add a custom look and feel as well as even just a tiny bit of dynamic content to my "static" core site pages. (e.g. I like the context_bar on all my site pages)

If I want to use ADP for reasons listed above, but also want the benefits of the StaticPages, General Comments and/or SiteWideSearch -- do I still have to manually find a solution to do what StaticPages does (for HTML) to my ADP pages?

I see how Joel's "straw man" works for a package but what about ADP pages that do not belong to a package but just serve content? I guess I need to get them stuffed in the CR in the database (only if I want SiteWideSearch?) and get an object id for them (to use General Comments).

Because after reading the using adp versus html thread, it seems like this has been discussed for a couple years, by experienced OACS folks, and solutions have been implemented. Are their solutions not implemented in OACS today? If so, it concerns me that there may be even more to this that I am not understanding. Being new to OACS I don't want to unknowingly corrupt my OACS datamodel...

Posted by Andrew Piskorski on
Some related discussion is going on in Benjamin Jensen's question about static pages thread.
Collapse
Posted by Avni Khatri on

I also needed general comments on my adp pages. I didn't want to have to put all my adp pages in a separate package just to get an object_id, so I ended up doing the following:

1. Added adp as a file extension in the param AllowedExtensions in the static-pages package
2. Went to /static-pages/admin and clicked "scan the file system for static pages". This gives all my adp pages under www a page_id.
3. I then used Joel's method of adding a comment to notes (see above) and applied it using the page_id of my adp pages.

Collapse
Posted by Pavel Boghita on
Thanks Joel, this is a brilliant piece of information - exactly what I was looking for
Collapse
Posted by yo ha on
Joel,

In relation to the piece of code to grab the comments and displaying it in the adp page, when i tried to use your code the comments were displayed with plain text format in the adp page. The HTML tags were not interpreted. Is there something that im missing???

*****
code to grab the comments from the object with id $temp
set comments_html [general_comments_get_comments -print_content_p 1 -print_attachments_p 1 $temp]

*****
adp page

<a href="@comment_link@">Add a comment</a>
<p>@comments_html@

Thanks.

Collapse
Posted by Brian Fenton on
Hi Yo Ha
You need to noquote your variable in the adp:

@comments_html;noquote@

Brian

Collapse
Posted by yo ha on
Brian,

Thanks again. It now displays what i want.