In Freemarker how do I insert the right number of spaces to place text in a specified column?

StackOverflow https://stackoverflow.com/questions/21590512

  •  07-10-2022
  •  | 
  •  

I'm doing some simple C code generation using Freemarker. I am generating a line like the following:

#define MY_CONSTANT                   (0)

From a template of the form:

#define ${name}                   (${value})

I am generating a bunch of these and I want them to come out like this

#define MY_CONSTANT                   (0)
#define MY_NEW_CONSTANT               (42)
#define MY_OTHER_CONSTANT             (101)

With the values all column aligned. Is there an easy way to do this? Do I need to write a directive for it?

Thanks in advance.

有帮助吗?

解决方案

You can use the right_pad builtin.

#define ${name?right_pad(30)} (${value})

See the doc here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top