Substitutions
On this page
In Snooty, you can use variables to represent a text value in the rendered form of the documentation. These variables are called source constants. When used consistently, they help prevent inconsistencies in formatting the term and make it easy to change the value for all its occurrences.
For example, you can use a substitution to represent the name of a MongoDB
product, like Compass. with a variable, descriptively named gui-tool
.
If the product name changes, you only need to update the value of the
variable gui-tool
to update all the instances of "Compass" in the
documentation site.
Source Constants
Source constants define substitution text for variables in reStructuredText files. When building the documentation, the substitution text replaces the instances of the variables prior to Docutils parser transforming the document to HTML. You can use source constants within directives and roles.
You can add or modify source constants in your documentation repository's
snooty.toml
file in the base directory. Source constants should be
defined in the [constants]
section using in the
<name> = "substitution text"
format.
For example, suppose you want to add a source constant that represents the
URL to the MDN documentation, "https://developer.mozilla.org/en-US/docs/MDN/".
If you name the source constant "mdn", your snooty.toml
file should
include the following line in the [constants]
section:
mdn = "https://developer.mozilla.org/en-US/docs/MDN/"
Use the source constant as shown in the following example:
Read the `Game development <{ +mdn+ }Games>`__ article on MDN for information on creating web games.
Important
In your reStructuredText, source constants shouldn't contain spaces between curly braces and plus signs as shown in the example. The spaces were intentionally added to the example to prevent the parser from substituting a value.