Forum OpenACS Development: using global var among files

Collapse
Posted by Iuri Sampaio on
I need to set a variable within a TCL page that has its content appended within another TCL file.

As in:

File item-ae.tcl
#####
ad_page_contract { ...}

global item_id_list ""

...

new AjaxUpload(btnUpload, {
action: 'append-item',
data: { item_id: $('#item_id').val()},
name: 'appenditem',

...

####

Within the TCL file "item-ae.tcl", I have an AJAX code that requests "append-item.tcl" eventually.

The ajax chunk has a form that sends data ("item_id") which will be submited as a form to the file "append-item.tcl" and there the item_id value is appended in the list "item_id_list"

#####
ad_page_contract { ...} {
{item_id}
}

lappend item_id_list $item_id

####

Back to the TCL file "item-ae.tcl", I need the content of the variable "item_id_list" to have the "item_id" appended recently in the previous request file.

Which means to have "item_id_list" working as a global variable among two pages

Is that possible?
How would I do that?

Collapse
Posted by Jeff Rogers on
If your global variable is going to be used in two different requests (item-ae and append-item) then you can't share the data with a tcl variable. Not only because the two requests don't share this sort of state, but if two users are trying to work at the same time they would almost certainly clobber the other's idea of the correct variable.

You could either persist the item_id_list to your database, or have the client store the data (either through cookies or client-side javascript variables) until you're ready to persist it.

Collapse
Posted by Dave Bauer on
ad_set_client_property
ad_get_client_property

Use these to set a server side variable for a particular request. Check out the docs you can key it to the URL or a relevant key.