# Create different documents from the same ReST sources (conditional text)

> **Note: Specialist technique**
>
> This tutorial is specific to the Sphinx and reStructuredText toolchain. It is most useful if you maintain Sphinx-based documentation; the underlying idea, conditional content from a single source, is also implemented by DITA XML's ditaval mechanism (see the [NuFirewall case study](https://docs.redaction-technique.org/en/formats/nufirewall-case-study/#provide-targeted-information-with-ditaval-conditional-text)).

## Objective

This approach uses Sphinx's built-in `only` directive rather than a [Jinja preprocessing script](https://docs.redaction-technique.org/en/tutorials/conditional-text-jinja/), which makes the workflow simpler for straightforward cases.

1.  Install *Sphinx*, and *make*:

    ```bash
    $ sudo apt install python3-sphinx make
    ```

2.  Create a Sphinx project using the default options:

    ```bash
    $ sphinx-quickstart
    ```

3.  Add the following content to the `index.rst` file, maintaining the correct indentations:

    ```txt
    .. only:: electrician

       .. admonition:: Danger for electricians

          Risk of electrocution

          Do not touch electrical wires.

    .. only:: plumber

       .. admonition:: Danger for plumbers

          Risk of drowning

          Do not dive into the pool.
    ```

4.  To control the display of content intended for electricians or plumbers, uncomment or comment the following lines in the `conf.py` configuration file:

    ```python
    tags.add('electrician')
    tags.add('plumber')
    ```

5.  Generate your content:

    ```bash
    $ make html
    ```

6.  Open the `_build/html/index.html` file in a browser to view your content.

## Related articles

- [Create different documents from the same sources via Jinja (object method)](https://docs.redaction-technique.org/en/tutorials/conditional-text-jinja-object-method/)
- [Automatically insert data into a reStructuredText file](https://docs.redaction-technique.org/en/tutorials/auto-insert-data-restructuredtext/)
- [Regular expressions in Python](https://docs.redaction-technique.org/en/tutorials/python-regular-expressions/)

---

Source: https://docs.redaction-technique.org/en/tutorials/conditional-text-sphinx-rest/
