[AOLSERVER] using variable in adp file

6 views
Skip to first unread message

Xavier Bourguignon

unread,
Mar 15, 2008, 6:10:17 PM3/15/08
to AOLS...@listserv.aol.com
Hi,

I have a variable set in my tcl code. e.g: set uname "myuname"

how do I use this in my adp page?. e.g: Your username is: <%puts $uname%>

It does not seem to work, everytime i get a tcl error saying that
uname does not exists. I tried to make uname global, to no avail.

Thank you

--
Xavier Bourguignon


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <list...@listserv.aol.com> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.

Bas Scheffers

unread,
Mar 15, 2008, 8:51:18 PM3/15/08
to AOLS...@listserv.aol.com
The correct way to just access a variable is:

<%= $variable %>

No need for "puts". This works also:

<%= [clock seconds] %>

Which puts the output of that command in the HTML.

But it sounds like you have a scope problem. Any way you can post your
actual code?

If you set the variable inside a procedure, you could use "upvar" to
make it available in the scope where you want to display it. If you
put a variable in the global scope, you can access it like so:

<%= $::variable %>

Bas.

Xavier Bourguignon

unread,
Mar 16, 2008, 5:26:00 AM3/16/08
to AOLS...@listserv.aol.com
Thanks for the answer Bas.

I have done this now: set ::variablename value

in adp: if {$::variablename} {
blah
}

so it works now, but I have no idea as to why I should explicitly add
the :: for this to work. The tcl code runs in a function which has
been registered like this: ns_register_filter postauth.

Thank you

Xavier Bourguignon

unread,
Mar 16, 2008, 6:02:34 AM3/16/08
to AOLS...@listserv.aol.com
Bas, i forgot to attach my code, here is the procedure, it is called
at the beginning of every request.

proc ::gs_admin::req_init {conn arg why} {
variable INIT
global REQ

catch {unset REQ}

if {!$INIT} {
ns_log Waning "==>::gs_admin::req_init - gs_admin must be
initialised before use..."
return
}

ns_log Notice "==>Starting request"

# check the user is logged in
set logged_in [::gs_login::logged_in $conn]

if {[lindex $logged_in 0]} {
set REQ(LOGIN_OK) 1
} else {
set REQ(LOGIN_OK) 0
set REQ(LOGIN_REASON) [lindex $logged_in 1]
}

# everything is fine, lets carry on
return "filter_ok"
}

what happend now is that in my adp file I call: <% if {$REQ(LOGIN_OK)} { %>
and I get this error:
can't read "REQ(LOGIN_OK)": no such variable
while executing
"if {$REQ(LOGIN_OK)} {

Very weird indeed.

Is there a way to find out which scope the code is in at any one point
in the execution?

Thank you

Bas Scheffers

unread,
Mar 16, 2008, 6:57:18 AM3/16/08
to AOLS...@listserv.aol.com
Well, this should work. Normally, anything between <% %> is executed
in the global scope and as $REQ is in the global scope it should be
accessible.

I noticed you are using the new parser that allows you to do "... { %>
some html <% } ...", something I have never done. Could it be this
works differently and every block is executed in a different scope?
(i.e.: parsed into a proc and then executed)

Bas.

Xavier Bourguignon

unread,
Mar 16, 2008, 2:46:51 PM3/16/08
to AOLS...@listserv.aol.com
I am sorry, wouldn't know about this, I am very new to aolserver. I
set my singlescript param to 1 because I prefer it that way, may be
there is something there indeed.
Reply all
Reply to author
Forward
0 new messages