Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle undefined values in docxtemplater or javascript object array

I have an object array that will be exported to word document via DocXTemplater

Sample array

[
    {Name:"jon doe",age:27},
    {Name:"joe roe",age:27,Address:"new jersey"}
]

Now the template will be

{#arrayVarName}{Name},{age},{Address}{/arrayVarName}

This should output,

Jon,27,undefined
Joe,27,new jersey

Now I want to filter all undefined and replace them with either empty string or some custom string, how can this be done in docxtemplater, or can all the undefined in object array be replaced with custom string?

like image 245
Vignesh Subramanian Avatar asked Oct 29 '25 17:10

Vignesh Subramanian


1 Answers

You can now customize this setting globally :

const doc = new Docxtemplater(zip, {nullGetter() { return ''; }});
like image 74
edi9999 Avatar answered Oct 31 '25 05:10

edi9999



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!