Re: Pass through of optional parameters
"Daniels, Troy (US SSA)" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
> -----Original Message----- > From: [email protected] > [mailto:[email protected]] On > Behalf Of Daniel Dekany > Sent: Wednesday, May 14, 2008 4:22 AM > To: FreeMarker-user > Subject: Re: [FreeMarker-user] Pass through of optional parameters > > Wednesday, May 14, 2008, 10:01:00 AM, Attila Szegedi wrote: > > > *Sigh*. No, you can't do it, as FreeMarker mandates that all > > expressions used as arguments to a macro invocation resolve to a > > defined value. I wish we'd change that, at least for > optional arguments. > > > > Jonathan, Daniel - opinions? > > I my un-implemented language there is, shown with FTL syntax: > > <@theMacro theParam!noarg> > > So, there was special value (special like null is) that means > that the parameter (or list/map item!) is omitted. Overly > smart, one could say... but also quite useful. But it still > doesn't solve that the user has requested in this thread. The > thing is, if you do know that a variable potentially missing, > you have to indicate that in the source code everywhere you > refer to that variable; it has trivial maintainability > related reasons, so I'm reluctant to give it up. In my case, if I get to a point where I want to use the optional variable and it's not there, it's a bug (either in the template or the input) and dieing horribly is an acceptable response. > I don't see > how could it be a reason to relieve this rule that the > variable reference happens to be used as a parameter. Now, in > the case of FreeMarker 2.3, the problem is, that even if the > user accepts this philosophy of strictness, he simply can't > indicate that "I know this variable is possibly missing, and > in that case please consider the whole parameter being > omitted". But starting from FreeMarker 2.4, you can write > theParam?null. What's the timeline for 2.4 being released? > It's a dirty solution, as it doesn't exactly > behave as if the parameter were omitted, but practically it > will be OK on the quality standard where FreeMarker lives. > It will certainly work well enough for me. Troy > > Attila. > > > > On 2008.05.13., at 20:53, Troy Daniels wrote: > > > >>> > >>> I have a macro with an optional parameter: > >>> > >>> <#macro term source result op context optional...> > >>> do stuff, possibly using ${optional.root} </#macro> > >>> > >>> This is called indirectly by another macro. > >>> > >>> <@indirectCall root=someValue /> > >>> > >>> <#macro indirectCall optional... > stuff <@term source=s result=r > >>> op=o context=c ???/> </#macro> > >>> > >>> I'd like to pass through the optional parameter when it's > given to > >>> indirect. At the moment, the best way that I can see to > do that is > >>> > >>> <#macro indirectCall optional... > > >>> stuff > >>> <#if optional.root??> > >>> <@term source=s result=r op=o context=c > root=optional.root /> > >>> <#else > >>> <@term source=s result=r op=o context=c /> </#if> </#macro > >>> > >>> Is there a more concise way of doing this? I tried <@term {other > >>> args} optional=optional>, but that just meant that the > optional map > >>> in @term had a key called optional, pointing to the map I > wanted it > >>> to be. > >>> > >>> I can write it like this, but it rather clutters macros > that aren't > >>> trying to do anything except convey the optional parameters down. > >>> It'll get even more cluttered if I add a second optional > parameter. > >>> > >>> Troy > >> > >> > >> Also, does anyone know if the > >> [email protected] address is active? I > >> tried posting this from my work account (which receives > messages just > >> fine) but I got a bounce message like I wasn't subscribed. I sent > >> mail there asking about the problem, but I haven't heard back from > >> it. > > -- > Best regards, > Daniel Dekany > > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > FreeMarker-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/freemarker-user > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/