Skip to content

Reuse content with conref and conkeyref

Write a note, step or paragraph once in a chunks file and pull it into any topic. The build inlines it, and every page that uses it updates together.

  1. Put reusable elements, each with an id, in a topic under reuse/.
    <topic id="common">
      <title>Reusable content</title>
      <body>
        <note id="restart" type="note">Restart the web service and the worker after changing a variable.</note>
        <steps>
          <step id="step-build"><cmd>Build the packages: <codeph>pnpm build</codeph>.</cmd></step>
        </steps>
      </body>
    </topic>

    Leave the file out of every map. A chunks file is not published on its own, and validation does not warn about it as long as some published topic uses one of its chunks.

  2. Pull a chunk in with conref, using the path, the topic id and the element id.
    <note conref="../../reuse/common.dita#common/restart"/>
  3. Or define a key for the chunks file once, and use conkeyref so topics need no relative paths.
    <!-- in a map -->
    <keydef keys="reuse" href="../reuse/common.dita"/>
    
    <!-- in any topic -->
    <step conkeyref="reuse/step-build"/>

    This page itself pulls its restart note in with conkeyref:

How references behave:

  • References work within a file and across files, and chunks may reference other chunks. Cycles are reported as conref-cycle.
  • The referencing element should have the same name as the chunk. A <p> that pulls a <note> works but warns (conref-type-mismatch).
  • Filtering attributes on the referencing element apply to the pulled content, so <note conkeyref="reuse/restart" product="core"/> shows the shared note to core readers only. Attributes on the chunk itself apply too.
  • Keys inside a chunk resolve in the keyspace of the map publishing the topic that pulls it.
  • conrefend and conaction are not supported: only the start element is pulled, with a warning.

The release snapshot records which topics use each chunk, so tools can show the impact of changing one.