You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dave Dutcher <dj...@earthlink.net> on 2002/07/06 19:12:32 UTC

Foreach syntax and whitespace

Hello,

I'm using Velocity to generate some html, and I have a script like this:

#foreach($email in$email_list)
<p>$email</p>
#end

And it works great, but I am trying to enter the VTL directly into a WYSIWYG
html editor.  Maybe I will have to edit the html file once the editor is
done with it, but I'd like to avoid that so I don't have to re-edit the html
file everytime I change something with the editor.  Sometimes though the
editor will end up splitting the foreach line like this:

#foreach($email
in$email_list)
<p>$email</p>
#end

Then when I try to merge the html file with a VelocityContext I get an
exception.

I tried doing this:
#foreach($(email)in$email_list)

but that didn't work either.  It seems that Velocity needs a space, (not a
CR/LF) between $email and in and nothing else will work.  Is that true, or
is there something I'm missing?

Thanks,

Dave


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Foreach syntax and whitespace

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

A tip that I've found works with my editor (Dreamweaver) is to insert VTL 
within a HTML comment whenever I can.  Often the so called comment is preserved 
with no changes to spaces or returns.


<!--  #foreach($email in $email_list)  -->
 <p>$email</p>
<!--  #end  -->

Of course, this outputs as the following, which displays fine in the browser.

<!--    -->
 <p>email1</p>
 <p>email2</p>
 <p>email3</p> (etc)
<!--   -->

WILL

Quoting Dave Dutcher <dj...@earthlink.net>:

> Hello,
> 
> I'm using Velocity to generate some html, and I have a script like
> this:
> 
> #foreach($email in$email_list)
> <p>$email</p>
> #end
> 
> And it works great, but I am trying to enter the VTL directly into a
> WYSIWYG
> html editor.  Maybe I will have to edit the html file once the editor
> is
> done with it, but I'd like to avoid that so I don't have to re-edit the
> html
> file everytime I change something with the editor.  Sometimes though
> the
> editor will end up splitting the foreach line like this:
> 
> #foreach($email
> in$email_list)
> <p>$email</p>
> #end
> 
> Then when I try to merge the html file with a VelocityContext I get an
> exception.
> 
> I tried doing this:
> #foreach($(email)in$email_list)
> 
> but that didn't work either.  It seems that Velocity needs a space, (not
> a
> CR/LF) between $email and in and nothing else will work.  Is that true,
> or
> is there something I'm missing?
> 
> Thanks,
> 
> Dave
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 



------------------------------------
Will Glass-Husain  <wg...@forio.com>
Forio Business Simulations
office: (415) 440-7500
mobile: (415) 235-4293

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>