Re: Returning String without Whitespace from Velocimacros

Alex Fedotov <[email protected]> Thu, 1 Aug 2013 13:43:12 -0400
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <CAHKxnLGBQ-fzMVeP_--0fp-Gs6TgNP=45c_+GKZRj-Z4fZ-i8w@mail.gmail.com>
Simple way:

#set($str="#default_query_url()")
$str.trim()

Can probably create a helper macro "trim" that does the same thing to the
body content:

#@trim()
   #default_query_url()
#end




On Thu, Aug 1, 2013 at 1:27 PM, O. Olson <[email protected]> wrote:

> Hi,
>
> I am new to using Apache Velocity. What is the correct way of returning a
> string from a Macro or a Velocimacro?
>
> Since I did not have a clue on how to return a string from a Macro, I
> decided to do something like
> #macro(query_url $query_param) q=$query_param #end
>
> I can then call the Macro using: #query_url("*")
>
> The problem with this is that the resulting value contains a Tab or
> number of Spaces before the 'q=' when I call it.
>
>
> One option is to delete the spaces like:
> #macro(query_url $query_param)
>        q=$query_param
> #end
> This fixes my problem but is very hard to read.  To take this a step
> further consider:
> #macro(default_query_url) #if($request.params.get('q'))
> #query_url($request.params.get('q')) #else #query_url("*") #end #end
> Vs.
> #macro(default_query_url)
>     #if($request.params.get('q'))
>           #query_url($request.params.get('q'))
>     #else
>           #query_url("*")
> #end
> In the first case there is no whitespace, but editing it would be very
> difficult for more complicated macros.
>
> I am curious what is the correct way to return values from Velocimacros
> and if I can Trim the resulting Whitespace before returning it?
>
> Thank you an advance for any help.
> O. O.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>