velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leos Literak <liter...@centrum.cz>
Subject scope of introduced variables
Date Mon, 04 Mar 2002 10:46:32 GMT
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

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.

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 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.

	Leos


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message