How to define attributes with the same key for different modules?

133 views Asked by At

I want to use the same key attribute in different module, but the value is different.

I defined attribute in antora.yml , but it seems no way to distinguish modules.

What should I do?

1

There are 1 answers

0
eskwayrd On

Attribute definitions in antora.yml are global to the component containing antora.yml. There is no way to target those attributes to a specific module. But they are easily overridden within the page that uses them.

For example, if you define an attribute in antora.yml:

asciidoc:
  attributes:
    foo: bar

Then wherever you use {foo} in your component's pages, you'd see bar in the generated HTML.

To override that in a specific page:

:foo: FOO

When the {foo} attribute is encountered anywhere on the same page, after that definition, you'd see FOO in the generated HTML.

If you have multiple pages in a module that need to share the same definition, you can place those definitions into a separate Asciidoc file, say attributes.adoc. If you place that file into the module's partials folder, you can include it on any module page that requires the attribute definitions with:

include::partial$attributes.adoc[]

You don't have to define all attributes within attributes.adoc, only the ones that need to be redefined for the module.