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.
About this task
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.
-
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"/> -
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
keywordorlinktextin itstopicmeta, 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. -
Validate.
An undefined key in
keyrefis a warning,unresolved-key, and the element's own content is used as a fallback. An undefined key inconkeyrefis an error.
Results
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.