Templates and fields

Replace clauses from your application

Replace a tagged block-level field from application-owned UI.

Use a block-level content control as a clause slot. The DOCX owns where the clause appears. Your application owns the available clauses and chooses which content fills that slot.

Try a clause slot

Choose a clause below. The Editor replaces the paragraph inside the control tagged agreement.confidentiality.

Choose a confidentiality clauseOpening document...
Clause library

Replace the clause

For a complete project, use the Add fields example. Create the block field, then choose Use mutual confidentiality clause. The paragraph changes while its tag remains.

Continue with an Editor that has finished loading, and use superdoc.activeEditor.doc as doc. The clause sample already contains the required slot; the Quickstart sample does not. Create src/replace-clause.ts with this helper and call it from your clause picker:

Find the slot by tag, require one block-level control, then replace its content:

import type { BrowserDocumentApi } from 'superdoc/ui';

export async function replaceClause(doc: BrowserDocumentApi, tag: string, content: string) {
  const { items } = await doc.contentControls.selectByTag({ tag });

  if (items.length !== 1) {
    throw new Error(`Expected one content control tagged "${tag}", found ${items.length}.`);
  }

  const [control] = items;
  if (control.kind !== 'block') {
    throw new Error(`Content control "${tag}" must be block-level.`);
  }

  return doc.contentControls.replaceContent({
    target: control.target,
    content,
    format: 'text',
  });
}

replaceContent() changes the content inside the control. Its tag and ID remain attached to the slot. Inspect the mutation receipt before updating your application UI.

In the current Editor, replacement content is rebuilt as text. Keep each replaceable clause to one paragraph. Your application can store approval state, versions, and clause metadata outside the DOCX.

Export through your existing load and save flow. Reopen the saved DOCX and confirm that the chosen paragraph and its agreement.confidentiality tag remain.

Continue with Lock template fields to keep a clause slot or its contents from being removed. Use the Document API reference for every content-control operation.

On this page