in reply to Perl CGI and Template Toolkit

One rather clever trick is to pass a function.   Specifically, it can be a closure.   (Google it...)   When TT sees a template-variable it is actually smart enough to know when that “variable” is a function-reference and if so it will call that function.   A “closure” can access the local variables of whatever it was contained-in.   It can on-the-fly populate other, “real,” variables that are also referred-to in the template.