You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Greg Coladonato <gc...@yahoo.com> on 2001/03/27 04:09:08 UTC

help with word wrapping in templates

I'm using Velocity to generate some text emails.
One issue that I have is that the dynamic text
is of variable length, so it's hard to include it
in the middle of a paragraph and still have the lines
be approximately the same length.

It seems to me that a step after .merge() that 
tokenized and wraped words based on a desired max line
length would do the trick, but I'm not sure what the
best way to hack it in would be.

Has anyone needed to do this before, and if so, how
did you do it? FYI, I'm using the VelocityEmail 
class in Turbine.

Thanks,
Greg

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Re: help with word wrapping in templates

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Greg Coladonato wrote:
> 
> I'm using Velocity to generate some text emails.
> One issue that I have is that the dynamic text
> is of variable length, so it's hard to include it
> in the middle of a paragraph and still have the lines
> be approximately the same length.
> 
> It seems to me that a step after .merge() that
> tokenized and wraped words based on a desired max line
> length would do the trick, but I'm not sure what the
> best way to hack it in would be.
>
> 
> Has anyone needed to do this before, and if so, how
> did you do it? FYI, I'm using the VelocityEmail
> class in Turbine.

I would assume a little helper tool is your best bet.  You should be
able to apply it to the stream post merge, or do something kooky like
use it in the template.

First thing that comes to mind, if you wrap the entire message
generation in a simple macro :

#macro( mailmessage )

  Your $message is $this.

#end

then you can capture the whole body in a string, and then you can apply
your tool :

#set($mymailmessage = "#mailmessage()" )
$mailtool.justify( $mymailmessage )

or

$mailtool.justify( "#mailmessage()" )

if lazy...

This works because by default, Velocity will 'interpolate' anything
between double quotes, including Velocimacros.  So the reference
$mymailmessage will hold whatever the macro mailmessage would have
rendered to the output.

Of course, you may be looking for another solution where you don't have
to write the tool :)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: help with word wrapping in templates

Posted by Jon Stevens <jo...@latchkey.com>.
on 3/26/01 6:09 PM, "Greg Coladonato" <gc...@yahoo.com> wrote:

> Has anyone needed to do this before, and if so, how
> did you do it? FYI, I'm using the VelocityEmail
> class in Turbine.
> 
> Thanks,
> Greg

This is really a Turbine-User question...

I think that your idea of wrapping the output from Velocity is the best way
to go here. You can override the VelocityEmail class with your own class or
submit a patch that adds a method to the VelocityEmail
class...setWrapping(int length)...with 0 to be no wrapping. Then implement a
wrapping method as well. :-)

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>