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

Hi Eduard,
I did something similar in past
only difference:

  • used #q1c1#  to make sure placeholders are embedded and don't conflict  with the real text
  • my table was in HTML with default row visibility HIDDEN
    only with actual content, it was set to VISIBLE.
    This allowed also to skip rows and have not only uniform rows
    and I could also play with styles.