Forum OpenACS Q&A: Include tag, key issue for package inter operability

Hi All,
Recently in a project with Caroline we have used some packages and integrated ones with others, we usually found ourselves writing pages with includes from other packages pages.

But the include is not always an easy way to reuse the code from other package because most of them must be modified (and probably you don't want to modify them), specially because the pages are written to work by themselves (in the package page-flow) and not for being used as includes, that's specially true in the templates and in the variable passing (forms/urls, POST/GET).

I think the best possible way is to define an special include that will fool that kind of pages, taking out their original master template & handling well the form & url variable passing between them, in this way you avoid changing the actual code of any package that you might use; the other possible way will be to change to a special ad_page_contract & and changing the master tag, but this is probably not the most elegant way to handle this.

The real cool thing if is defined a new include tag will be to:

  • Override automatically the package master template and put instead the callers master template or for the most of the cases, just do not use that package master template.
  • Make it able to handle all the variable passing (urls, post/get), probably with some sort of proc like rp_form_put
  • The ability to make it return to a URL that you want after or before some page is called in that package.
  • The possibility to send the package mapped directory, in order to identify to which instance of that package you want, so you can manage multiple instances of the same package for your application.

This is a real need for openacs and for any of the related projects.

Anyone has thoughs about this?

Collapse
Posted by Dave Bauer on
I think the key to making it work with the existing code is to program the pages to alwasy us an include. So the default object display page of the package would have the a page that inteprets ad_page_contract and then calls the include. This includable page could then be used in other places.

The existing forums message display works like this. The message display template is included for each message in a thread.

So, I am not sure if we need a new tag, or to change the way the current tag works, or if we can just change the way we build our pages.

I definitely agree that reusable page components are a great idea and we need to promote more use of includable adps.

Collapse
Posted by Dave Bauer on
I had another related idea. Custom ADP tags. Instead of <include src="survey-page" survey_id="@survey_id@"> we could also define custom tags that include the templates.

I am not sure that is so much a programmer convenience. I was thinking more of allowing the use of these tags for through-the-web editing of content templates for a CMS, so a designer or editor could add features to a page.

Collapse
Posted by Ola Hansson on
Having packages use includes for its templated pages is probably a very good idea. For one, it makes it easy to write dotLRN applets.

Sometimes it's not even necessery to interpret ad_page_contract in the .tcl page script, if you use an include for the page. A single .adp page may call the include (oftentimes without any parameters at all) and let the ad_page_contract in the .tcl page of the include pair do all the interpreting ...

This may become especially convenient if the include handles optional keys, such as in a combined ad_form add/edit kind of page (where the existence of a key suggests to ad_form it should render an "add form" and vice versa) because you won't have to worry about whether to convey the key or not as a property, it's all handled by the include.

YMMV,

Yes, it's an excellent point.  For one project, I separated the login (and I think registration) forms so that they could be used as included "widgets" in various places throughout the site.  Very helpful.