Forum OpenACS Q&A: master.tcl Template Scope

Posted by James Thornton on
I have this proc loaded from openacs/tcl/moto-procs.tcl...

proc moto_dealer { var } {

    set dealer_id [moto_get_dealer_id]
    array set moto_dealer [nsv_array get moto_dealer]
    return $moto_dealer($dealer_id,$var)

If I call it from normal Tcl page such as index.tcl, it works fine. But, if I call it from a template page such as master.tcl, I get this error:

can't read "moto_dealer(73,name)": no such element in array

Posted by Randy O'Meara on
So, what is [nsv_array get ...] returning differently under the two circumstances? Maybe the nsv array moto_dealer is somehow not set when you call it from the wrapping template due to some difference in execution logic? The code sure looks ok to me.
Posted by russ m on
without knowing how you're indexing moto_dealer it's a bit hard to guess, but I'd suspect that the literal "name" in your error is perhaps meant to be the content of a var called "name"... Is the call to moto_dealer perhaps
set foo [moto_dealer name]
where it should be
set foo [moto_dealer $name]