velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
Subject Re: scope of introduced variables
Date Mon, 04 Mar 2002 11:07:42 GMT
On 3/4/02 5:46 AM, "Leos Literak" <> wrote:

> Hello,
> I'd like to know, if you are planning any changes
> of scope of variables introduced in template.
> I've got following problems:
> 1\
> ($b=='str', $c=null)
> #set($a=$b)
> $a
> #set($a=$c)
> $a
> result: str str
> I have to be careful about variable names.
> I shall not use them again, because they
> are not zeroed, when setting to null variable.
> I'd prefer to unset variable, if right side
> is null. If for any reason you don't want this,
> please create #unset

This is a subject of recent discussion.   We are going to fix soon.

> 2\ velocimacro
> #macro (showArticle $relation $last)
> #set($clanek=$relation.Child)
> #set($dizs=$UTIL.filterDiscussions($clanek.Content))
> #if($dizs.size()>0)
> #set($diz=$dizs.get(0).Child)
> #end
> $!UTIL.showDate($!UTIL.getXPath($clanek,'/data/published'))
> $!UTIL.getXPath($clanek,'/data/perex')
> Comments:
> #if($diz)
> $diz.Content.size()
> #else
> 0
> #end
> #end
> When $diz or $dizs are initialized for first time, $diz is always
> used in following invocations, until they are reset by new value.
> The result is of course wrong.
> Yes, I know, there is configuration key for macros local scope.
> But I can't use it, because few of my macros forwards data to next
> macro in chain:
> #macro(first $b)
> #set($c=$b.Data)
> $b.OtherData: #second($c)
> #end
> and when I set local scope to true, such macros stopped working.

What stops working?  Passing data from 'first' to 'second'?

In the first case, why can't you initialize the references to be sure?
> Again, it could be fixed with explicit #unset, but I'd prefer
> to have new tag for local scope variables.
> Something like
> #macro(my $a)
> #setTemp($count=$a.Content.size())
> $a, $count
> #end
> What do you think? I'm tired of making workarounds and hacks to these
> limitations. I think, Velocity is really great product and I like it.
> But sometimes it is too simple :-(

I think the solution will be a way to unset or clearly remove from the
context a reference...  I personally don't like #unset() if we can solve
with a more useful technique like a 'NULL' (so we can compare to it as

> I will try to watch this thread over HTTP, if I found web interface
> to this archive. If you want to ensure, I will see your comments,
> cc my email, 'cause I'm not in this conference.

I will cc you once with this, but out of courtesy, if you want to be sure to
get responses, please subscribe.

Geir Magnusson Jr.                           
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message