Forum OpenACS Development: Intrigued by a Tcl variable scope

Collapse
Posted by Iuri Sampaio on

Writing a piece of code where a listtemplate is not aware of page variables, I noticed the fact that passing product_ids through include calls do work and the values show in the ADP page. However, there are no such variables within listtemplate's scope.

i. passing product_ids through the include:

<include src="/packages/evex-event/lib/events" product_ids="@product_ids@">
ii. As expected, the value of product_ids arrives in .../lib/events, and showed in the browser (adp file) ex.
@product_ids@
...
<listtemplate name="events"></listtemplate>
However, when used within a listtemplate it returns "no such variable". See the chunk of code written in the ad_proc template::list::create
...
action {
            label "Acoes"
            display_template {
                <button class="button-add" id="button-proposal" 
                 onclick="javascript:window.location.replace('send-proposal?event_id=@events.event_id@&product_ids=@product_ids;noquote@ ');">
                 #evex-event.Send_proposal#</button>
                <br><br>
                <if events.admin_p>
                ...
            }
        }
...
Does that mean db_multirow's scope isn't aware of page variables?

How do I bring the page variables into listtemplate's scope?

[07/Aug/2018:23:02:38][2470.7f65ca7fc700][-conn:evex:3:3883-] Error: Error in include template "/var/www/evex/packages/evex-event/lib/events": can't read "product_ids": no such variable
    called from adp_parse_ad_conn_file
    called from rp_serve_concrete_file /var/www/evex/packages/evex-event/www/request-proposal.adp
Collapse
Posted by Iuri Sampaio on
Thanks Gustaf,

It turned out that I change the approach and wrote another script. I've added a form, and the variable is within a hidden input. Instead of an argument in the link, which now is the submit form button and holds another id.

I guess those 3 lines below explain much better what I've written above.

 <form method="post" name="request_proposal" action="request-proposal-2" >
       <input type="hidden" name="product_id" id="product_id" value="@product_id;noquote@" >
       <include src="/packages/evex-event/lib/events" >
...
Collapse
Posted by Iuri Sampaio on
Thanks again Gustaf,
I've got another scenario to use list::create -pass_properties.
It works very well.

...
list::create \
-name events \
-multirow events \
-pass_properties { admin_p } \
...

Collapse
Posted by Iuri Sampaio on
Gustaf,

Instead of list::create, wouldn't the best place be in the db_multirow?

Or even, the switch pass_properties could be in both. Couldn't it?

Collapse
Posted by Gustaf Neumann on
The flag is especially for variables used in the list template, which are NOT part of the multirow (or db_multirow). The template::list iterates of the multirow tuples and needs the information, what other variables have to be provided in the "display_template".

Without looking at the details, it might be possible to modify the implementation of "display_template" to include all global variables, but - maybe for a good reason - this was not done at the first place.