Re: Field length formatting
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Monday, April 26, 2010, 4:16:59 PM, Kjeld 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? Yes, see http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_left_pad > 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 -- Best regards, Daniel Dekany ------------------------------------------------------------------------------