Re: A WM brain bender
Keats Kirsch <[email protected]>
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Message-ID | <[email protected]> |
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
>
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click