// set custom template symbols in a DOCX template

import { CreateDocx } from "../../../build";
import * as fs from "fs";

const docxTemplate = fs.readFileSync(
    "../../files/TemplateVariables_symbols.docx"
);

const docx = new CreateDocx();
// load the template
docx.openTemplate(docxTemplate).then(docx => {
    // set a custom template symbol
    docx.setTemplateSymbols("${", "}");

    // variables to be replaced
    const variables = new Map<string, string>();
    variables.set("VAR", "New value");

    // replace variables
    docx.replaceVariableText(variables);

    // save the DOCX
    docx.save().then(contents => {
        fs.writeFileSync("setTemplateSymbol_1.docx", Buffer.from(contents));
    });
});
