Table of Contents

Class PlaceholderExtensions

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

Fills {{name}} placeholders in document text from a set of values.

A placeholder is ordinary text, so this inherits everything FindReplaceExtensions guarantees: a placeholder may be split across any number of runs — which Word does routinely, for reasons that have nothing to do with its words — the substituted value inherits the placeholder's formatting and revision mark, and the surrounding runs are coalesced afterwards. It may not cross a field, hyperlink, content control or image boundary.

Scope is the root you call it on. These hang off DomNode, not WordDocument. Called on a document they reach the body, headers, footers, footnotes, endnotes and text inside shapes — so a letterhead header is filled too. Called on a Table, a TableRow or a TableCell they touch nothing outside it, which is how one table among many is filled.

One pass. Every placeholder is substituted in a single scan, so a value that itself contains something shaped like a placeholder is never substituted into. Filling key by key instead would make the output depend on the order the keys happened to be enumerated in.

A placeholder names at least one character, so an empty {{}} names nothing and is left alone by every action including Clear.

This is deliberately a flat substitution: no conditionals, no repetition, no nested records. A template that needs a region repeated per record wants DocWright.MailMerge, where that grammar already lives.

public static class PlaceholderExtensions
Inheritance
PlaceholderExtensions
Inherited Members

Methods

FindPlaceholderNames(DomNode, PlaceholderOptions?)

Lists the placeholder names a template asks for, without substituting anything.

ReplacePlaceholders(DomNode, IReadOnlyDictionary<string, object?>, PlaceholderOptions?)

Substitutes every placeholder whose name the values supply.