You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Saimon Moore <sa...@yahoo.co.uk> on 2002/04/14 19:21:28 UTC
horizontal foreach output
Hi..
Is there anyway to get the #foreach directive to do a print rather than
a println i..e
From this
#foreach ($letter in $alphabet)
<a href="xxx">$letter</a>
#end
Can I get the output to be:
A B C D E F G H I J K L ...
instead of
A
B
C
D
E
F
G
H
...
I could easily create a tool and stick it in the context to do it I
suppose..but I was wondering if there was a way to do it with just vtl...
cheers...
Saimon
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by Saimon Moore <sa...@yahoo.co.uk>.
I've come up with a quick work around i.e.
$letters = $letters + $link
where $link = <a href="xxx">$letter</a>
that works well ...but perhaps there's a switch in order to get foreach
to to print rather than println..
Saimon
Saimon Moore wrote:
> Hi..
>
> Is there anyway to get the #foreach directive to do a print rather than
> a println i..e
>
> From this
>
> #foreach ($letter in $alphabet)
> <a href="xxx">$letter</a>
> #end
>
> Can I get the output to be:
>
> A B C D E F G H I J K L ...
>
> instead of
> A
> B
> C
> D
> E
> F
> G
> H
> ...
>
> I could easily create a tool and stick it in the context to do it I
> suppose..but I was wondering if there was a way to do it with just vtl...
>
> cheers...
>
> Saimon
>
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by Christoph Reck <Ch...@dlr.de>.
Hi,
I'm the one trying to get a quorum for a better whitespace handling,
more embedded...
Saimon Moore wrote:
>
> Hi..
>
> Is there anyway to get the #foreach directive to do a print rather than
> a println i..e
>
> From this
>
> #foreach ($letter in $alphabet)
> <a href="xxx">$letter</a>
> #end
You are writing your anchor tag in its own line, so velocity will
render it that way. So you either write it:
#foreach ($letter in $alphabet)<a href="xxx">$letter</a> #end
or
#foreach ($letter in $alphabet)
<a href="xxx">$letter</a>##
#end
or use a macro:
#macro( text $string )$string#end
#foreach ($letter in $alphabet)#text(<a href="xxx">$letter</a>)#end
and with my proposed whitespace handling you will also be
able to do nicely formatted vtl:
#foreach ($letter in $alphabet)
#text(<a href="xxx">$letter</a>)
#end
>
> Can I get the output to be:
>
> A B C D E F G H I J K L ...
voilĂ
Note the neatest way to put up a list is:
#set( $sep = "" )
#foreach ($letter in $alphabet)
$sep<a href="xxx">$letter</a>##
#set( $sep = ", " )
#end
To get
A, B, C, D, E, F, G, H, I, J, K, L, ..., Z
>
> instead of
> A
> B
> C
> D
> E
> F
> G
> H
> ...
>
> I could easily create a tool and stick it in the context to do it I
> suppose..but I was wondering if there was a way to do it with just vtl...
>
> cheers...
>
> Saimon
Hope this helps...
And hope may people say:
+1 "yes we agree with Christoph's whitespace handling!"
William, the #text(...) macro would also help you on your link!
(you could call it #escapeURL or similar...)
--
:) Christoph Reck
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by Mark de Reeper <ma...@yahoo.com>.
Just took a quick look at my source for this (typing from memory is never a
good idea), you may need to add some "" to the example to cast the result to a
String:
#set( $link = "#link('home')" )
Cheers
Mark
--- William Bajzek <w_...@yahoo.com> wrote:
>
> --- Mark de Reeper <ma...@yahoo.com> wrote:
> > Another workaround to the macro problem is to do a set on the result and
> then
> > trim the string since it is a real String object by then.
> >
> > From your example:
> >
> > #set( $link = #link("home") )
> > <a href="$link.trim()&somethingelse=1">
>
> I thought you couldn't use a macro inside another macro... I'll have to give
> it
> a try.
>
> =====
> William Bajzek
> http://william.bajzek.com/
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/14/02 10:55 PM, "William Bajzek" <w_...@yahoo.com> wrote:
>
> --- Mark de Reeper <ma...@yahoo.com> wrote:
>> Another workaround to the macro problem is to do a set on the result and then
>> trim the string since it is a real String object by then.
>>
>> From your example:
>>
>> #set( $link = #link("home") )
>> <a href="$link.trim()&somethingelse=1">
>
> I thought you couldn't use a macro inside another macro... I'll have to give
> it
> a try.
You can nest VMs until the proverbial bovine reenter the domicile.
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by William Bajzek <w_...@yahoo.com>.
--- Mark de Reeper <ma...@yahoo.com> wrote:
> Another workaround to the macro problem is to do a set on the result and then
> trim the string since it is a real String object by then.
>
> From your example:
>
> #set( $link = #link("home") )
> <a href="$link.trim()&somethingelse=1">
I thought you couldn't use a macro inside another macro... I'll have to give it
a try.
=====
William Bajzek
http://william.bajzek.com/
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by Mark de Reeper <ma...@yahoo.com>.
William,
Another workaround to the macro problem is to do a set on the result and then
trim the string since it is a real String object by then.
>From your example:
#set( $link = #link("home") )
<a href="$link.trim()&somethingelse=1">
Cheers
Mark
--- William Bajzek <w_...@yahoo.com> wrote:
> As far as I know, the best you can do is:
>
> #foreach ($letter in $alphabet)<a href="xxx">$letter</a> #end
>
> Which is not very readable. I'm more frustrated by the fact that something
> like...
>
> #macro(link $page)
> http://www.blah.blah/servlet/something?page=$page
> #end
>
> ...when used as such:
>
> <a href="#link("home")&somethingelse=1">
>
> sometimes produces:
>
> <a href="http://www.blah.blah/servlet/something?page=$page
> &somethingelse=1">
>
> or
>
> <a href="
> http://www.blah.blah/servlet/something?page=$page
> &somethingelse=1">
>
> which often causes problems with browsers.
>
> I end up having to define the macro like this:
>
> #macro(link $page)http://www.blah.blah/servlet/something?page=$page#end
>
> which is a lot harder to read.
>
> =====
> William Bajzek
> http://william.bajzek.com/
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Tax Center - online filing with TurboTax
> http://taxes.yahoo.com/
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: horizontal foreach output
Posted by William Bajzek <w_...@yahoo.com>.
As far as I know, the best you can do is:
#foreach ($letter in $alphabet)<a href="xxx">$letter</a> #end
Which is not very readable. I'm more frustrated by the fact that something
like...
#macro(link $page)
http://www.blah.blah/servlet/something?page=$page
#end
...when used as such:
<a href="#link("home")&somethingelse=1">
sometimes produces:
<a href="http://www.blah.blah/servlet/something?page=$page
&somethingelse=1">
or
<a href="
http://www.blah.blah/servlet/something?page=$page
&somethingelse=1">
which often causes problems with browsers.
I end up having to define the macro like this:
#macro(link $page)http://www.blah.blah/servlet/something?page=$page#end
which is a lot harder to read.
=====
William Bajzek
http://william.bajzek.com/
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>