docx-templates
docx-templates copied to clipboard
Special characters like in docx template
- When I use a docx with a
?
character as template, it throws an error.
Erro: Error executing command 'name?': SyntaxError: Unexpected end of input
DOCX file: "your name is {name?}"
CODE:
createReport({template, data: {name: "Jonathan"}})
- running on NodeJs 16.16.0 - Ubuntu
How can I use ?
and other special characters in a docx template?
Why do you want a ?
.
name?
is not valid JavaScript so the error is expected...
Because users will create the templates. They need to write a question to be replaced.
For example, I have a user that wants to use {what is your name?}
I'm wondering if I can disable the javascript feature and just use the replament feature.
That is not possible. All between {...} has to be valid JS.
I never had user-provided templates. But you can create a list of valid fields where you can document the complete stuff...
Basicly what you need is a preprocessor-feature where you get the content between {...} and return valid JS code. (would be a hook into it here https://github.com/guigrpa/docx-templates/blob/master/src/processTemplate.ts#L476 )
I strongly sugest not to do this. But if you need it that would be your entry-point into implementing it.
Thanks for replying @mathe42 ! Closing this because it seems answered.