Re: Recursion within webmacro templates

Alex Twisleton-Wykeham-Fiennes <[email protected]> Tue, 7 Mar 2006 10:01:42 +0000
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
On Tue 7 March 2006 09:48, Holger King wrote:

<snip>

> is it even possible to access plugged in WebContext-Tools like URLTool
> within a "templet" directive like
>
> >#templet $counter {
> >  #set $digit = $digit + 1
> >  #if ($digit < 10) {
> >    [$digit < 10]
>
>              $URL.getRequestURL()?counter=$digit

Yes it is possible to access variables from the main context.  You use a 
syntax like so (I've also fixed typos in previous copy paste):-

#set $outsidevariable = "finished!"
#templet $counter {
  #set $digit = $digit + 1
  #if ($digit < 10) {
    [$digit < 10]
    #eval $Self using { "digit": $digit }
  } #else {
    [$OuterVars.outsidevariable]
  }
}
#eval $counter using { "digit": 0 }

gives:-

[1 < 10] [2 < 10] [3 < 10] [4 < 10] [5 < 10] [6 < 10] [7 < 10] [8 < 10] [9 < 
10] [finished!]

For more docs see here:-
http://www.webmacro.org/TempletDirective

Alex


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642