Source Constants
The substitutions built into restructuredText have a number of limitations and quirks. For example, they cannot be used to substitute content inside of code blocks, and cannot contain links.
The MongoDB Documentation Project has an extension called
source_constants
which allows you to substitute constants anywhere
in a page before docutils begins its parse stage.
Example
In your conf.py
, add 'source_constants'
to the extensions
list, and define a source_constants
dict:
1 source_constants = { 2 'package-branch': 'testing', 3 'package-name-org': 'mongodb-org', 4 'version': version 5 }
You may then use these constants in your restructuredText files:
Create the ``/etc/apt/sources.list.d/mongodb-org-4.4.0.list`` list file using the command appropriate for your version of Ubuntu: .. code-block:: sh echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu \ trusty/mongodb-org/testing multiverse" \ | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Comparison with Other Variable Syntaxes
4.0 | {{version}} | |version| | |
---|---|---|---|
Description |
| Giza YAML substitutions | |
Locations | Can be used anywhere | Can only be used within YAML files | May only be used in a subset of restructuredText syntactical locations |
Valid Content | Anything | Anything | May not be used to inject links or other non-trivial types of content |
Mutable | Can currently only be defined in | Yes. Can be overridden with Giza's content inheritance mechanism | Can only be defined once per page context |
Warns if undefined | Yes | No | Yes |