Question
· Jun 18, 2018

Filling document templates - what's your approach?

Let's say I have a user-generated document template with placeholders and I want to replace them with actual values.

Values could be:

  • scalars
  • tables
  • ...?

So far I wrote a simple find/replace tool that works with RTF format (because it's not a binary format), here's how it works:

set template = "D:\Cache\RTF\template.rtf"
set var("%title") = "Hello"
set var("%table") = $lb("Utils.RTF", "TestFunc")
set result = "D:\Cache\RTF\out.rtf"
set sc = ##class(Utils.RTF).replace(template, .var, result)

There should be two placeholders in RTF template: %title and %table and the are replaced with "Hello" and  results of Test query from Utils.RTF class, serialized into a table.

Template:

Output:

 

But I'm wondering if someone has already done something similar and can recommend a better approach?

What I'm most interested in is how do you work with preset tables, i.e. I have this template and need to produce the output above (instead of one %table template where I generate everything, part of the table is already present):

Discussion (2)0
Log in or sign up to continue