Re: A WM brain bender

Keats Kirsch <[email protected]>
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
Looking back at the old TemplateTool code, it does what you want, but 
not in a particularly elegant way:

#set $m = $Template.fromString($content.Data)
$m.eval({ "contextData": $someData })

For some reason the MacroTemplate class doesn't implement the Macro 
interface.  This would be a simple change that would allow you to say:

#set $m = $Template.fromString($content.Data)
#eval $m using { "contextData": $someData }

I could make this change if anyone is interested.

Keats

Marc Palmer wrote:

> Hi,
>
> Long time no speak!
>
> I finally got around to getting 2.0b1 (only a year late!) and am 
> working on the start of CMS using WM.
>
> I wonder if I'm being really stupid, but I want some of the content, 
> which is pulled in from String data, to be treated as a WM template.
>
> So given a content string loaded from the CMS, say "<p>Hello, 
> $name</p>", I want to use this in my page, a template itself, but have 
> $name evaluate. i.e. something like this in the main CMS rendering 
> template:
>
> <div>
>    #eval $content.Data using { "contextData": $someData }
> </div>
>
> ...but eval only works with Macro objects to my knowledge.
>
> Does anybody know how I can do this? I effectively want the same as 
> #include but from a String instead of a file.
>
> I've tried:
>
> <div>
>    #templet $block
>       $content.Data
>    #end
>    #eval $block using { "contextData": $someData }
> </div>
>
> ...but of course this is not correct as $content.Data is not evaluated 
> at the time the templet is defined. I also tried #setblock as macro etc.
>
> It's a bit confusing. I'd like to not have to write a helper/directive 
> to load a Macro tempalte from a String unless I have to...
>
> Thanks in advance.
>




-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.