Re: Returning String without Whitespace from Velocimacros

"O. Olson" <[email protected]> Thu, 1 Aug 2013 22:07:17 +0100 (BST)
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
Thank you very much Sergiu for that detailed explanation of
the limitations of Velocity Macros.



----- Messaggio originale -----
Da: Sergiu Dumitriu <[email protected]>
A: [email protected]
Cc: 
Inviato: Giovedì 1 Agosto 2013 13:13
Oggetto: Re: Returning String without Whitespace from Velocimacros

> This is a macro with a body:
> http://velocity.apache.org/engine/releases/velocity-1.7/vtl-reference-guide.html#amacro_-_Allows_users_to_define_a_Velocimacro_VM_a_repeated_segment_of_a_VTL_template_as_required
> 
> The full code would be:
> 
> #macro(trim)
> $!bodyContent.trim()
> #end
> 
> #macro(default_query_url)
> ... your normal macro body, with all the extra space ...
> #end
> 
> Calling it:
> 
> #@trim()#default_query_url()#end


I think I understood everything you said except the above code i.e. I could not get it to work. In the link you posted above, I did not clearly understand what a VM with a body meant. I thought any non-trivial VM needed to have a body i.e. you cannot have a meaningful function in java be void function(){} or something like that.


To attempt this in my global library I put something like:

#macro(query_url $query_param)
    q=$query_param
#end

#macro(trim) 
$!bodyContent.trim() 
#end 

In my template, I called this using: 

#@trim()#query_url("sometext")#end 


The result seems to be:
q=sometext

i.e. there are spaces in the front that I don't like.Any ideas what I am doing wrong. 


Thank you again,
O. O.