You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Scott Edward Skinner <ss...@cloud9.net> on 2005/09/09 15:59:04 UTC

Local variables; string concatenation within macro calls

Can you define local variables in Velocity--variables that do not 
reference anything from the controller?

Can you perform concatenation within a macro call. For example...

#someMacro($request.getContextPath() + "/static")

S     |\_._/|     .-.
E     | o o |_   / /
S   _.(  T  ) `./ /
---(((-`-(((---------


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


Re: Local variables; string concatenation within macro calls

Posted by Will Glass-Husain <wg...@forio.com>.
Hi,

String concatenations (with the + operator) works in #set statements. 
However, no operators are allowed in macro parameters (use references only).

This works:
###########################
#set($param="test" + "abc" )

#macro(mac $item)
item: $item
#end

#mac($param)

###########################

This doesn't.
###########################
#set($param="test" )

#macro(mac $item)
item: $item
#end

#mac($param + "abc")

###########################


Will

----- Original Message ----- 
From: "Jean Francois Chamard" <jf...@interstructure.ca>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, September 09, 2005 8:29 AM
Subject: Re: Local variables; string concatenation within macro calls


> Hi,
> Wasn't there the #local command in the last nightbuilds for this?
>
>
> Nathan Bubna wrote:
>
>>On 9/9/05, Scott Edward Skinner <ss...@cloud9.net> wrote:
>>
>>>Can you define local variables in Velocity--variables that do not
>>>reference anything from the controller?
>>>
>>
>>yes.  #set( $foo = "hello world!" )
>>
>>
>>>Can you perform concatenation within a macro call. For example...
>>>
>>>#someMacro($request.getContextPath() + "/static")
>>>
>>
>>not like that.  do this:
>>
>>#someMacro( "${request.contextPath}/static" )
>>
>>
>>>S     |\_._/|     .-.
>>>E     | o o |_   / /
>>>S   _.(  T  ) `./ /
>>>---(((-`-(((---------
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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


Re: Local variables; string concatenation within macro calls

Posted by Jean Francois Chamard <jf...@interstructure.ca>.
Hi,
Wasn't there the #local command in the last nightbuilds for this?


Nathan Bubna wrote:

>On 9/9/05, Scott Edward Skinner <ss...@cloud9.net> wrote:
>  
>
>>Can you define local variables in Velocity--variables that do not
>>reference anything from the controller?
>>    
>>
>
>yes.  #set( $foo = "hello world!" )
>
>  
>
>>Can you perform concatenation within a macro call. For example...
>>
>>#someMacro($request.getContextPath() + "/static")
>>    
>>
>
>not like that.  do this:
>
>#someMacro( "${request.contextPath}/static" )
>
>  
>
>>S     |\_._/|     .-.
>>E     | o o |_   / /
>>S   _.(  T  ) `./ /
>>---(((-`-(((---------
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>  
>

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


Re: Local variables; string concatenation within macro calls

Posted by Nathan Bubna <nb...@gmail.com>.
On 9/9/05, Scott Edward Skinner <ss...@cloud9.net> wrote:
> Can you define local variables in Velocity--variables that do not
> reference anything from the controller?

yes.  #set( $foo = "hello world!" )

> Can you perform concatenation within a macro call. For example...
> 
> #someMacro($request.getContextPath() + "/static")

not like that.  do this:

#someMacro( "${request.contextPath}/static" )

> S     |\_._/|     .-.
> E     | o o |_   / /
> S   _.(  T  ) `./ /
> ---(((-`-(((---------
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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