Re: Field length formatting
Rune <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I believe this is what you want:
http://freemarker.sourceforge.net/docs/ref_builtins_string.html#ref_builtin_left_pad
Example:
${"Foo"?left_pad(15)}
Best regards,
Rune
On Mon, 26 Apr 2010 16:16:59 +0200, Kjeld <[email protected]> wrote:
>
> Hello,
>
> I am new to Freemarker and I am trying to output a value in a predefined
> length format, in particular have Freemarker add trailing spaces to meet
> a
> specified string length. E.g. value 'Foo' should become ' Foo'
> when specifying a length of 15.
>
> Does Freemarker provide in such a method/function?
>
> I was able to create a macro that does the trick, but I am curious if
> such a
> function exists already in the framework.
>
> <#macro format size><#local nestedContent><#nested></#local><#if size gt
> nestedContent?length><#list 1..size - nestedContent?length as n>
> </#list><#nested><#else><#nested></#if></#macro>
>
> Usage: <@format size=15>Foo</@format>
>
> Thanks,
> Kjeld
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
------------------------------------------------------------------------------