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
  •  | 
  •  

Question

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.

Was it helpful?

Solution

You can use the right_pad builtin.

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

See the doc here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top