Daniel Rall wrote:
>
> "Geir Magnusson Jr." <[EMAIL PROTECTED]> writes:
>
> > "Geir Magnusson Jr." wrote:
> >
> > > So I propose :
> > >
> > > When you call a VM with a non-existant reference, the rendered output
> > > will be simply the *literal form of the corresponding VM arg* if
> > > rendered in the VM, and #if() will work correctly - namely the value is
> > > null.
> > >
> > > An example :
> > >
> > > #macro( foo $a )
> > > ->$a<-#if($a)yes#end
> > > #end
> > >
> > > When called with a real value :
> > >
> > > #set($lala = "hello")
> > > #foo($lala)
> > >
> > > output
> > >
> > > ->hello<-yes
> > >
> > > and when called with something not in the context
> > >
> > > #foo($notincontext)
> > >
> > > output
> > >
> > > ->$a<-
> >
> > As a follow up - I think some may initially object to this behavior as
> > it's different than a regular reference in that you get the VM arg
> > reference rendered ($a) rather than the passed-in reference rendered
> > when it's null ($notincontext).
> >
> > I think this is ok - because unlike a regular reference in a template,
> > where we render 'as is' because it is not a reference if not backed by
> > data in the context (ex. $ave at our $ale on $aturday! ), in a VM, it
> > is clearly intended to be a reference because it's the formally declared
> > arg to the VM, so I think there is no harm in rendering the arg
> > reference token ($a, above) vs the arg reference.
>
> I must confess that I am much more used to the opposite behavior,
> where the symbolic reference $a first evaluates to the symbol
> $notincontext, then $notincontext renders literally because it's not
> in the context. However, I would be okay with either of these forms,
> so long as the behavior is clearly defined in the documentation.
>
I'm (and I guess we all are, because that's the way it works...) used
to it too.
However, I can't see how that is the desired behavior. The reason I say
this is because you are in a Velocimacro and you are using in the body
of the VM the 'arg variable'. Therefore, we know you aren't trying to
do something like
$ale!
The only useful bit about rendering '$notincontext' rather than '$a' is
that it helps you debug. How about we address this with a message
generated to the log (default off?) that says something like :
Velocimacro arg $foo is null
or something?
Then we get the debuggability as well as #if() w/o having to complicate
things...
geir
--
Geir Magnusson Jr. [EMAIL PROTECTED]
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!