How bout this:

#macro(get $things)
    #set($didRun = "0" )
    #foreach($thing in $things)
        ## do something...
        
        #set($didRun = "1" )
    #end


    #this will test if the above loop was executed and if not
    #but the variable is not null then it must be single object.

    #if( $didRun == "0" && $things )
        #do whatever you would do above
    #end

#end


I didn't test that so I don't know if it works.

Hope this helps,
Sayed Ibrahim Hashimi
www.cise.ufl.edu/~sih

-----Original Message-----
From: e v a n l e o n a r d [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 02, 2005 2:14 PM
To: 'Velocity Users List'
Subject: RE: "For each" on an object?



I guess its just a usability thing.  To be able to pass a single string
would avoid careless errors, that's all. I may settle for what you suggest
though.
-Evan
 

-----Original Message-----
From: Sayed Hashimi [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 1:45 PM
To: Velocity Users List
Subject: RE: "For each" on an object?

Hi,
Why don't you just assign $things to an array with 1 element instead of just
to the string object?
If you do this then you definitely shouldn't have problems.

Hope this helps,
Sayed Ibrahim Hashimi
www.cise.ufl.edu/~sih

-----Original Message-----
From: e v a n l e o n a r d [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 02, 2005 1:42 PM
To: velocity-user@jakarta.apache.org
Subject: "For each" on an object?



Hello,

I am trying to create a macro that can either take a single string
parameter, or an array of strings.

The code looks something like this:

#macro(get $things)
    #foreach($thing in $things)
        ## do something...
    #end
#end


What I would like to happen is that if $things is only a single object and
not a collection, for it to be assigned to $thing, and then the inner code
run only once. This way foreach loops would be useful over more variable
input.

Has there been any thought about this already? Or, how would others solve
this problem?

Sincerely,
Evan Leonard




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to