I'm searching for some clues on the usage of closures in geekLog Templates.
First, the documentation of what is doable with the caching Template is somewhat obscure. It should be possible to eliminate all language variables in the software:
Text Formatted Code
// and the template
<tr><td>{lang_username}:</td><td>{username}</td></tr>
// becomes
<tr><td>{$LANG_USER[name]}:</td><td>{username}</td></tr>
Than I do assume that {$myVar} also works when it is in global scope. So far so good.
Reading carefully, there is another great feature about global functions:
Text Formatted Code
So while a simple if might look like this{!if var}, the advanced if can look like this{!if {var} == 'a' || {var} == 'b' !}.
Advanced actions are closed by standard {!endaction} constructs.
Complex conditions can also contain calls to any global function:
{!if COM_isAnonUser({uid}) !}
The parameter to the function is even a templated variable. Very good.
But further below in the wiki doc (in the table), it is documented that advanced actions are coded like
Text Formatted Code
Advanced Actions
{!!if condition !!} The condition can contain any template construct that does not end with !}.
Now, to the quest: I would like to set a templateVariable to contain a anonymous function.
Text Formatted Code
$foo = function() { return 'hello'; };
$tpl->set_var('foo', $foo);
Assuming this would work, would this output 'hello'?
Text Formatted Code
{!!echo condition !!} Echo's the complex condition to the cached PHP output.
i.e. {!!echo {foo} !!}
i.e. {!!echo {$foo} !!}
i.e. {!!echo $foo !!}
An alternative is, of course, to put the code between <?php and ?>.