From: Keats K. <ke...@xa...> - 2005-03-11 19:40:42
|
Marc Palmer wrote: > Keats Kirsch wrote: > >> Continuing the conversation with myself ... >> >> Another interesting option would be to change the #eval directive to >> work with Strings as well as Macros. (I would automatically convert >> the String to a StringMacro). This would be a simple change. The >> only downside is that it might make it a bit harder to catch some >> errors. >> >> Then you could simply say: >> >> #eval $content.Data using { "contextData": $someData } >> >> This is kind of cool. You could even do stuff like: >> >> #eval "Hello, $userName" using { "userName": $User.Name } > > > That would be the cleanest of them all. #eval was the first thing I > tried. > > However, is there a shortcut for #eval to make it pass in the caller's > context, so you don't have to pass all the stuff in? As documented on the Wiki pages, you can access variables from the callers context via the $OuterVars reference. You can also evaluate a templet (or any Macro) directly in the current context, e.g., #templet $t { Hello $User } $t This would work for your String case however, since you wouldn't have a Macro reference. You'd be back to converting the string to a Macro first. We could create a new option on #templet or #setblock, or a new directive like #stemplet to handle this, or fix the $Template tool as mentioned before. Or maybe a $toTemplet function would fit the bill? Keats > I know, it's less safe... but we live in an imperfect world ;-) > > Cheers > |