Conditional content
When reusing topics or pieces of content, you can add conditions to customize content based on the current instance or any custom filter.
Filter by instance
If a topic is used in several instances, you can specify elements that should or should not be included when building a specific instance.
Add the
instance
attribute to any element and list the instances separated by commas in which this element should be included. If you want to exclude an element from some instances, precede the list with an exclamation mark!
.<chapter title="Included everywhere" id="included_everywhere"> <p>This chapter and paragraph is included everywhere.</p> <if instance="foo,bar"> <p>This paragraph and the following image is filtered for instances `foo` and `bar`.</p> <img src="image.png" alt="Image"/> </if> </chapter> <chapter title="Excluded from `foo`" id="excluded_from_foo_" instance="!foo"> <p> This chapter is excluded from the instance `foo`. <if instance="bar">And this part of the paragraph is included only in `bar`.</if> </p> </chapter>## Included everywhere This chapter and paragraph is included everywhere. <if instance="foo,bar"> This paragraph and the following image is filtered for instances `foo` and `bar`. ![Image](image.png) </if> ## Excluded from `foo` {instance="!foo"} This chapter is excluded from the instance `foo`. <if instance="bar">And this part of the paragraph is included only in `bar`.</if>
Filter by custom conditions
When you include a snippet, you can specify custom filters that should apply for this specific include.
Add the
filter
attribute to any element in the snippet and specify a comma-separated list of custom filters.<snippet id="os_dependent_procedure_steps"> <step>Do this first</step> <step filter="macos">Step for macOS</step> <step filter="windows">Step for Windows</step> </snippet>Add the
use-filter
attribute when including the snippet.<procedure title="Install on macOS" id="install"> <include from="lib.topic" element-id="os_dependent_procedure_steps" use-filter="empty,macos"/> </procedure> <procedure title="Install on Windows" id="install"> <include from="lib.topic" element-id="os_dependent_procedure_steps" use-filter="empty,windows"/> </procedure>
Conditional titles
You can use use filters to adjust titles in reusable topics, chapters, procedures, and any other elements with titles.