Reference Document Attributes

You’ll likely use the value of a user-defined attribute entry or certain built-in attributes in specific locations throughout a document. To reference and use the value of a document attribute, you enclose the attribute’s name in curly brackets ({name-of-an-attribute}). This inline element is called an attribute reference.

Reference custom attributes

Before you can reference an attribute in a document it must be declared using an attribute entry in the document header. Let’s reference the two user-defined attributes set and assigned values in Example 1.

Example 1. Custom attributes set in the document header
= Ops Manual
:disclaimer: Don't pet the wild Wolpertingers. We're not responsible for any loss of hair, chocolate, or purple socks.
:url-repo: https://github.com/asciidoctor/asciidoctor

Once you’ve set and assigned a value to the attribute, you can reference that attribute throughout your document. In Example 2, the attribute url-repo is referenced twice and disclaimer is referenced once.

Example 2. Custom attributes referenced in the document body
Asciidoctor is {url-repo}[open source]. (1)

WARNING: {disclaimer} (2)
If you're missing a lime colored sock, file a ticket in
the {url-repo}/issues[Asciidoctor issue tracker]. (3)
1 Attribute references can be used in macros.
2 Attribute references can be used in blocks, such as admonitions, and inline. Since there isn’t a blank line between the disclaimer reference and the next sentence, the sentence will be directly appended to the end of the attribute’s value when it’s processed.
3 The reference to the url-repo-ex attribute is inserted into a longer URL address and used in a URL macro.

As you can see below, the attribute references are replaced with the corresponding attribute value when the document is processed.

Asciidoctor is open source.

Don’t pet the wild Wolpertingers. We’re not responsible for any loss of hair, chocolate, or purple socks. If you’re missing a lime colored sock, file a ticket in the Asciidoctor issue tracker.

Reference an automatically declared attribute

An automatically set document attribute is referenced the same way as an explicitly set document attribute. For instance, an AsciiDoc processor automatically sets these supported character replacement attributes. That means that you can reference them throughout your document without having to create an attribute entry in its header.

TIP: Wolpertingers don't like temperatures above 100{deg}C. (1)
Our servers don't like them either.
1 Reference the character replacement attribute deg by enclosing its name in a pair of curly brackets ({ }).

As you can see below, the attribute reference is replaced with the attribute’s value when the document is processed.

Wolpertingers don’t like temperatures above 100°C. Our servers don’t like them either.