You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by jeff <jl...@houseofdistraction.com> on 2000/12/20 02:29:49 UTC
invalid reference test?
I wanted to check in a template to see $foo was a valid reference. I
tried
#if (!$foo)
stuff
#end
then i tried
#if ($foo = null)
stuff
#end
then I tried
#if ($foo)
#else
stuff
#end
finally I suceeded with
#if ($foo)
#else
stuff
#end
Is there a more elegant solution?
Re: invalid reference test?
Posted by jeff <jl...@houseofdistraction.com>.
Ooops. My bad. My actual non-working template had
#if ( !$foo )
The problem was extra spaces inside the parenthesis. I assumed that
extra whitespace would be irrelevant and accidentally left it out of my
report.
"Geir Magnusson Jr." wrote:
>
> "Geir Magnusson Jr." wrote:
> >
> > jeff wrote:
> > >
> > > I wanted to check in a template to see $foo was a valid reference. I
> > > tried
> > >
> > > #if (!$foo)
> > > stuff
> > > #end
> > >
> >
> > You would think this would be the right way. Hm. I'll take a look.
>
> I must be missing something. The following template :
>
> #if (!$foo)
> Hello
> #end
>
> #set($bar = "woogie")
> #if(!$bar)
> not bar
> #else
> \$bar = $bar
> #end
>
> produces the output
>
> Hello
>
> $bar = woogie
>
> This seems right :) Maybe I didn't understand your post...
>
> geir
>
> > > then i tried
> > >
> > > #if ($foo = null)
> > > stuff
> > > #end
> > >
> > > then I tried
> > >
> > > #if ($foo)
> > > #else
> > > stuff
> > > #end
> > >
> > > finally I suceeded with
> > >
> > > #if ($foo)
> > >
> > > #else
> > > stuff
> > > #end
> > >
> > > Is there a more elegant solution?
> >
> > --
> > Geir Magnusson Jr. geirm@optonline.com
> > Velocity : it's not just a good idea. It should be the law.
> > http://jakarta.apache.org/velocity
>
> --
> Geir Magnusson Jr. geirm@optonline.com
> Velocity : it's not just a good idea. It should be the law.
> http://jakarta.apache.org/velocity
Re: invalid reference test?
Posted by Christoph Reck <Ch...@dlr.de>.
Note that if a
#set( $foo = "woogie" )
preceeded a
#set( $foo = $list.get(1000) )## nonexistent entry!
then
#if( !$foo )
All OK
#else
Why is \$foo = "woogie"?
#end
produces unexpected output.
So we need to consider changing from Hashtable to HashMap.
:) Christoph
> > This seems right :) Maybe I didn't understand your post...
> >
> > geir
>
> Maybe some more information about what Jeff's $foo object is would be
> helpful.
>
> :-)
>
> -jon
Re: invalid reference test?
Posted by Jon Stevens <jo...@latchkey.com>.
on 12/19/2000 7:29 PM, "Geir Magnusson Jr." <ge...@optonline.net> wrote:
> This seems right :) Maybe I didn't understand your post...
>
> geir
Maybe some more information about what Jeff's $foo object is would be
helpful.
:-)
-jon
--
Honk if you love peace and quiet.
Re: invalid reference test?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"Geir Magnusson Jr." wrote:
>
> jeff wrote:
> >
> > I wanted to check in a template to see $foo was a valid reference. I
> > tried
> >
> > #if (!$foo)
> > stuff
> > #end
> >
>
> You would think this would be the right way. Hm. I'll take a look.
I must be missing something. The following template :
#if (!$foo)
Hello
#end
#set($bar = "woogie")
#if(!$bar)
not bar
#else
\$bar = $bar
#end
produces the output
Hello
$bar = woogie
This seems right :) Maybe I didn't understand your post...
geir
> > then i tried
> >
> > #if ($foo = null)
> > stuff
> > #end
> >
> > then I tried
> >
> > #if ($foo)
> > #else
> > stuff
> > #end
> >
> > finally I suceeded with
> >
> > #if ($foo)
> >
> > #else
> > stuff
> > #end
> >
> > Is there a more elegant solution?
>
> --
> Geir Magnusson Jr. geirm@optonline.com
> Velocity : it's not just a good idea. It should be the law.
> http://jakarta.apache.org/velocity
--
Geir Magnusson Jr. geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity
Re: invalid reference test?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
jeff wrote:
>
> I wanted to check in a template to see $foo was a valid reference. I
> tried
>
> #if (!$foo)
> stuff
> #end
>
You would think this would be the right way. Hm. I'll take a look.
geir
> then i tried
>
> #if ($foo = null)
> stuff
> #end
>
> then I tried
>
> #if ($foo)
> #else
> stuff
> #end
>
> finally I suceeded with
>
> #if ($foo)
>
> #else
> stuff
> #end
>
> Is there a more elegant solution?
--
Geir Magnusson Jr. geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity