Re: A WM brain bender

Alex Twisleton-Wykeham-Fiennes <[email protected]>
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
On Friday 11 March 2005 13:16, 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...

Would it not be possible to have an implementation of TemplateProvider that 
used the name of the template as the contents of the template itself?

This would let you say:-

#include as template "<p>Hello, $name</p>"

or

#include as template "$templateSource"

Of course, this would rather cripple your normal template loading, so there 
could be a switch which looked for a given header such as:-

#include as template "evaluate:$templateSource"

and if it didn't start with "evaluate:" then it would just delegate the 
request to the default template loader.

If this fixed your problem then it would be relatively easy to implement...

Alex


-------------------------------------------------------
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.