Forum OpenACS Q&A: -query swith in ad_page_contract

The -query switch seems to have been omitted in the ad_page_contract api-doc. Has this been done on purpose?

Thanks for any hints,

Michael

Collapse
Posted by Brian Fenton on
That was news to me - thanks for pointing this out!
Collapse
Posted by Dave Bauer on
It is not really used, the first unamed argument after the docstring is the same as the -query section. I don't know if this was on purpose or not. Seems more like it was left off by convention and is stuck that way now.
Collapse
Posted by Jim Lynch on
Personally, when I first saw ad_page_contract it confused me... when I first saw -query, it undid all confusion and I use it every time.

CoreGuysnGals: pls don't get rid of it... imo, it goes to documentation

Collapse
Posted by Dave Bauer on
Jim. you might be right, but there are thousands of Tcl files without it, and few with it in the current code.

I suppose one could write a script to fix it, if one was so inclined.

I don't have an opinion either way.

Collapse
Posted by Brian Fenton on
Hi Jim,

can you give a simple example of how you use it?

thanks!
Brian

Collapse
Posted by Michael Martí Menzel on
Thanks to all for your explanations. Being a newbie, I was a little bit confused about the -query switch I've seen in some tcl-files (both in ]PO[ and in the OpenACS core files).

Best,

Michael

Collapse
Posted by Jim Lynch on
(from Brian Fenton: Jim, can you give a simple example of how you use it)

Brian, sure.

So if you use ad_page_contract without it, then you need two parameters like this

ad_page_contract { docs go here } { variables coming into the page (aka the query) go here } and other switches go here

example of "and other switches", I might use -properties, like this:

ad_page_contract { docs } { incoming } -properties { outgoing }

I like to use it this way:

ad_page_contract { docs } -query { incoming vars }

or if I want to document the vars available to the .adp:

ad_page_contract { docs } -query { incoming } -properties { outgoing vars }

-Jim

Collapse
Posted by Jim Lynch on
Heya Michael,

the -query { block } parameter is an alias for the unnamed second parameter of ad_page_contract

So you -could- do...

ad_page_contract {
docs
} -properties {
foo : onevalue
:
} -query {
{foo "default for foo"}
}

I.e., you can specify the switch parts in any order you want as long as the documentation block (which is unnamed) is first.

-Jim

Collapse
Posted by Brian Fenton on
Cheers Jim. I must start using the -properties more often. Good advice!
Collapse
Posted by Dave Bauer on
-properties sounds like a good idea :) Most modern openacs code doesn't use it as the common design pattern is for the ADP designer to be the same person as the Tcl programmer, in my experience.

Also there was some dreamed of feature to show the properties somehow in the documentation, that would be interesting.

Collapse
Posted by Brian Fenton on
"ADP designer to be the same person as the Tcl programmer"

AND the DBA, the sysadmin, the network guy plus office security 😉

Collapse
Posted by Steve Manning on
Wow you have someone else to make the tea? I'm jealous :)