cancel
Showing results for 
Search instead for 
Did you mean: 

Query regarding freemarker template

gudiyajain
Champ in-the-making
Champ in-the-making
HI,
I am using FTL for generating PDF. I am reading values from database and store into Map and iterate this map onto my ftl pAGE..
likE ${QuoteInfo.billingAddress}

here this value of address is coming as Vvaishali, ghfrfhf, Aruba, 656565

but I want it in

Vvaishali,
ghfrfhf,
Aruba,
656565

can anyone help me to display address like above format?
6 REPLIES 6

sanket
Champ on-the-rise
Champ on-the-rise
Refer this FTL guide.
Do let me know if it helps.

http://freemarker.org/docs/dgui_misc_whitespace.html

gudiyajain
Champ in-the-making
Champ in-the-making
thanks.
I alredy tried this one. but it was not working.

Hi,
try using the split function http://freemarker.org/docs/ref_builtins_string.html

split

It is used to split a string into a sequence of strings along the occurrences of another string.
For example:   
<#list "someMOOtestMOOtext"?split("MOO") as x>
- ${x}
</#list> 
will print:   
- some
- test
- text 
      
Note that it is assumed that all occurrences of the separator is before
a new item (except with "r" flag - see later), thus:      
<#list "some,,test,text,"?split(",") as x>
- "${x}"
</#list> 
      
will print:
   
- "some"
- ""
- "test"
- "text"
- ""        
split accepts an optional flags parameter, as its 2nd parameter. There's a historical glitch with the r (regular expression) flag; it removes the empty elements from the end of the resulting list, so with ?split(",", "r") in the last example the last "" would be missing from the output.


Regards,
Andrea

gudiyajain
Champ in-the-making
Champ in-the-making
Hi,
     I am facing one problem regarding  numbers in pdf creation using freemarker.
For eg.

Here is one variable
  grandTotal=2456789

I want to format it is like 245,678,9.00.

I am using two approaches:

1. ${grandTotal.string("0.00")}
     output= 2456789.00

2. ${grandTotal?string.number}
      output= 245,678,9

So How can I get 245,678,9.00 at one time?

or How can I combine both the approaches to get expected output?



rjohnson
Star Contributor
Star Contributor
You apporach ${grandTotal.string("0.00")} is correct, but you need a better format string. Freemarker uses Java decimal number format strings. Form memory ${grandTotal.string("###,###,0.00")} will do what you need.

kaynezhang
World-Class Innovator
World-Class Innovator
try
 ${grandTotal?string(",###.00")}