docs

Home All functions Legacy functions Categories

TokenMergeFileIntoFile()

Clarion prototype

Prototype: TokenMergeFileIntoFile(*CSTRING InSourceFile, *CSTRING InTargetFile, *CSTRING InToken, *CSTRING InReplacementFile, LONG InMergeFlags, LONG InContentFlags), SIGNED, PROC, PASCAL, RAW, NAME(‘TokenMergeFileIntoFile’)

Purpose

Reads a source template file, replaces token text with the full contents of another file, and writes the merged result to a target file.

Parameters

| Parameter | Type | Description | |—|—|—| | InSourceFile | *CSTRING | Source text or HTML template file to read. | | InTargetFile | *CSTRING | Target file to write. Must be different from InSourceFile so the template remains intact. | | InToken | *CSTRING | Full token text to replace, such as [[MessageBody]]. | | InReplacementFile | *CSTRING | File whose contents will be inserted where the token appears. | | InMergeFlags | LONG | Merge option flags. 0=Replace all, case-sensitive, 1=First only, 2=Ignore case, 3=First only and ignore case. | | InContentFlags | LONG | Replacement-content preparation flags. 0=Insert file contents exactly as read, 1=Convert replacement-file line endings to HTML <br> tags before insertion. Use 0 when the replacement file already contains HTML. Use 1 when the replacement file is plain text and you want its lines to render as separate lines inside HTML. |

Return value / error codes

Example files

EmailFrame.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
  <div style="text-align:center;">
    <img src="CompanyLogo.gif" alt="Company Logo">
  </div>

  <p>Dear [[CustomerName]],</p>

  <p>
    Here is your invoice for services performed on [[ServiceDate]].
    Thank you for your business.
  </p>

  [[PersonalMessage]]

  <hr>

  [[InvoiceBody]]

  <hr>

  <p>Company Name<br>
  Address<br>
  Phone</p>
</body>
</html>

InvoiceBody.txt

Invoice #12345
Service Date: 2026-04-27
Labor: $95.00
Parts: $12.50
Total: $107.50

Example (Clarion)

rc              LONG
templateFile    CSTRING(260)
mergedFile      CSTRING(260)
tokenText       CSTRING(80)
replacementFile CSTRING(260)
mergeFlags      LONG
contentFlags    LONG

templateFile    = CLIP(PATH()) & '\EmailFrame.html'
mergedFile      = CLIP(PATH()) & '\EmailMerged.html'
tokenText       = '[[InvoiceBody]]'
replacementFile = CLIP(PATH()) & '\InvoiceBody.txt'
mergeFlags      = 0   ! Replace all, case-sensitive
contentFlags    = 1   ! Convert replacement file line endings to <br>

rc = TokenMergeFileIntoFile(templateFile, mergedFile, tokenText, |
                            replacementFile, mergeFlags, contentFlags)
MESSAGE('TokenMergeFileIntoFile rc=' & rc)

Notes

Home All functions Legacy functions Categories