Can DITA templates include conditional content for different outputs?

DITA templates can indeed include conditional content for different outputs. Conditional processing in DITA allows for tailoring content to specific output formats, audiences, or conditions.

Conditional Content in DITA Templates:

Definition: Conditional content in DITA templates refers to the practice of embedding conditions within templates to control the visibility or inclusion of content based on specific criteria. These criteria can include output formats (e.g., PDF, HTML), audience (e.g., beginners, experts), or other conditions (e.g., product versions).

Importance: Conditional content is crucial for delivering tailored and audience-specific documentation. It ensures that readers receive relevant information while maintaining a single-source approach to content management.

Methods and Best Practices:

Conditional Text: In DITA, conditional text is often controlled through conditional processing attributes, typically @props or @audience. For example, it can be specified that a paragraph is visible in HTML output but excluded in PDF by applying the condition output=html.

Conref and Keys: Conref (content referencing) and keys can be used to pull in or exclude content blocks based on conditions. For example, a warning message might be referenced only if the document is intended for beginners.

Variables and Parameters: Variables and parameters can be defined within templates and set based on conditions. For example, a variable could control the inclusion of specific branding elements in different outputs.

Conditional Attributes: Some DITA publishing tools offer user-defined conditional attributes. Custom conditions can be created, allowing fine-grained control over content inclusion.

Example:

A software documentation project created using DITA needs to generate both online HTML help and printable PDF manuals from the same source content. It should conditionally include or exclude certain sections:

DITA Template with Conditional Content:


<topicref href="introduction.dita" output="html, pdf"/>
<topicref href="installation.dita" output="html"/>
<topicref href="user-manual.dita" audience="beginner" output="pdf"/>
<topicref href="advanced-features.dita" audience="expert" output="pdf"/>
    

In this example:

  • The output attribute specifies which output formats should include the referenced topic.
  • The audience attribute ensures that user-manual topics are included only in PDF outputs intended for beginners.
  • The template can be used to generate both HTML help and PDF manuals with the relevant content tailored to each output.

By incorporating these conditional attributes into their DITA templates, the documentation team ensures that each output format is optimized for its intended audience while maintaining content reusability.