0

In our read the docs project we have a use case where we need to show some specific docs on multiple pages in the same version of docs. As of now, we do this either by one of the following ways

  • Copy-pasting the content to each page's rst file
  • Write it in one of the concerned files with a label and use :std:ref: in rest of the files to redirect it to the main file

I would want to achieve something like writing content only in one file and then showing it (without any redirection for user) in each of the files. Is it possible?

Mukund Jalan
  • 1,145
  • 20
  • 39

2 Answers2

1

You can use for this purpose the include directive.

Say that you write the text in dir/text.rst.

The following will include in other documents:

..include :: /dir/text.rst

where the path is either relative (then, with no slash) or absolute which is possible in sphinx (doc)

in Sphinx, when given an absolute include file path, this directive takes it as relative to the source directory

Pierre de Buyl
  • 7,074
  • 2
  • 16
  • 22
1

Use the include directive in the parent file.

.. include:: includeme.rst

Note that the included file will be interpreted in the context of the parent file. Therefore section levels (headings) in the included file must be consistent with the parent file, and labels in the included file might generate duplicate warnings.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57