TemplatePart¶
featherdoc::TemplatePart is the shared editing surface for document body,
header, footer, and section-resolved parts. Use it when a workflow needs the
same template operation to work outside the main body, especially bookmark
filling, content-control replacement, and part-local template validation.
Common Tasks¶
Use this page as a part-local reference:
Fill named bookmarks: call
list_bookmarks(),find_bookmark(...),replace_bookmark_text(...), orfill_bookmarks(...).Fill content controls: use
find_content_controls_by_tag(...)andreplace_content_control_text_by_tag(...).Replace a template slot with generated content: use the bookmark or content-control replacement methods for paragraphs, tables, rows, and images.
Edit header/footer content with the same API as the body: get a
TemplatePartfromDocumentand then callparagraphs(),tables(),append_paragraph(...), orappend_table(...).Validate a local template surface: use
validate_template(...)before writing values.
Success And Failure Semantics¶
Return shape |
Success |
Failure or no-op |
|---|---|---|
|
|
|
|
Non-zero value is the count of matching slots changed or appended. |
|
|
|
|
|
Inspect |
Inspect |
|
Truthy result means required slots passed validation. |
Missing or mismatched slots are listed in the result details. |
Short Example¶
auto body = doc.body_template();
if (!body) return 1;
body.replace_bookmark_text("invoice_no", "INV-2026-001");
body.replace_content_control_text_by_tag("status", "approved");
Typed Signature Guide¶
Use TemplatePart for part-local editing. It is valid when
operator bool() returns true. Methods returning std::size_t report
how many matching bookmarks or content controls were changed. Methods returning
bool report whether the requested XML mutation was applied.
Signature |
Parameters |
Return semantics |
|---|---|---|
|
None. |
|
|
None. |
Package entry name such as |
|
|
New paragraph handle in the current part. |
|
|
New table handle in the current part. |
|
|
Matched, replaced, and missing-bookmark counts. |
|
|
Number of bookmark instances replaced. |
|
|
Number of matching controls replaced. |
|
|
Number of matching controls replaced with a table. |
|
|
Validation result with missing and mismatched slots. |
|
|
Created hyperlink count; |
Part Basics¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Return the package entry name for this part. |
|
|
Iterate paragraph content in the part. |
|
|
Append a paragraph with optional run formatting. |
|
|
Iterate table content in the part. |
|
|
Append a table with the requested shape. |
Bookmarks¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Enumerate bookmark slots in this part. |
|
|
Find one bookmark by name. |
|
|
Replace bookmark text and return the number of matched slots. |
|
|
Fill multiple bookmarks in one call and report misses. |
|
|
Replace a bookmark with paragraph content. |
|
|
Replace a bookmark with a generated table. |
|
|
Replace a bookmark with an image run. |
|
|
Show or hide the block that contains a bookmark. |
Content Controls¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Enumerate structured document tags. |
|
|
Find controls by business tag. |
|
|
Find controls by visible alias. |
|
|
Replace plain text in matching controls. |
|
|
Replace matching controls with paragraph content. |
|
|
Replace matching controls with a table. |
|
|
Replace matching controls with an image. |
|
|
Update checkbox, date, dropdown, combo-box, lock, or binding state. |
Template Validation¶
Method |
Returns |
Purpose |
|---|---|---|
|
|
Validate required bookmark and content-control slots. |
Document-Level Schema Workflows¶
validate_template_schema(...), scan_template_schema(...),
build_template_schema_patch_from_scan(...), and onboard_template(...)
are featherdoc::Document APIs because they can aggregate body, header,
footer, and section-targeted template slots. Use TemplatePart for part-local
slot filling and validate_template(...) checks, then use Document for
whole-document schema governance.
Example¶
auto part = doc.body_template();
auto result = part.fill_bookmarks({
{"invoice_no", "INV-2026-001"},
{"customer_name", "Ada Lovelace"},
});
part.replace_content_control_text_by_tag("status", "approved");
auto validation = part.validate_template({
{"invoice_no", featherdoc::template_slot_kind::text, true},
{"status", featherdoc::template_slot_kind::text, false},
});
if (!result.missing_bookmarks.empty() || !validation) {
return 1;
}
return doc.save_as("filled.docx") ? 1 : 0;