Skip to content

Use keys for names, links and images

Define a value once in a map, with keydef, and refer to it everywhere with keyref. Changing the map changes every page.

Keys suit product names, version numbers, external URLs, and topics that many pages link to. These docs keep theirs in maps/keys.ditamap and pull it into every map with a mapref.

  1. Define the key in a map.
    <!-- Variable text -->
    <keydef keys="product-name">
      <topicmeta><keywords><keyword>OpenD</keyword></keywords></topicmeta>
    </keydef>
    <!-- An external link with default link text -->
    <keydef keys="repo" href="https://github.com/desktopmachineshop/opend" scope="external" format="html">
      <topicmeta><linktext>the OpenD repository</linktext></topicmeta>
    </keydef>
    <!-- A topic -->
    <keydef keys="env-vars" href="../topics/hosting/env-vars.dita"/>
  2. Refer to it from a topic.
    <title><keyword keyref="product-name"/> overview</title>
    <p>Clone <xref keyref="repo"/>.</p>
    <p>See <xref keyref="env-vars"/>.</p>
    <image keyref="logo"><alt>Logo</alt></image>

    An empty element takes the key's text: the keyword or linktext in its topicmeta, or else the target topic's title, or else the URL. An element with its own content keeps that content and only takes the key's target.

  3. Validate.

    An undefined key in keyref is a warning, unresolved-key, and the element's own content is used as a fallback. An undefined key in conkeyref is an error.

When a key is defined more than once, this definition wins:

  • Within one map, the first definition in document order.
  • A map's own definitions win over those of the submaps it references.
  • Each map and bookmap has its own keyspace. A topic used by both the site map and a bookmap is compiled once, with the site map's keys.
  • A key may have several definitions with different conditions. Each reader gets the first one their filter keeps: see Conditional keys.

Key scopes are not supported yet.