On Tue, Feb 19, 2013 at 4:43 AM, Thomas Güttler <[email protected]> wrote:
> I want to use variables in reST: > > Example: > > Emails to $EMAIL_SUPPORT are forwarded to ..... > > I would like to set the variable in setup() of my config.py. > > How could this be done? > > Gunter (below), is on the right track. In your conf.py, define a rst_epilog ( http://sphinx-doc.org/config.html#confval-rst_epilog). Also define the variable you want to use (EMAIL_SUPPORT) in you example. Use regular python string formatting (either %-formatting or .format()) to interpolate your variable value into a "replace" substitution. Use the substitution in your reST documents. more specifically: in conf.py: email_support = "[email protected]" rst_epilog = """ .. |email_support| replace:: {0} """.format(email_support) Then in you reST document: Emails to |email_support| are forwarded to ..... When Sphinx processes your documents, it will append the rst_epilog to each document before processing it, so the substitution will be defined for each document, and the replacement text will get inserted just like a normal reST substitution would work. I realize this seems like a lot of effort for something that seems like it should be simple, but it's the only method I've come up with so far that doesn't involve writing an extension to do this. An extension wouldn't be terribly difficult by the way. I think it would just be a matter of creating a custom text role that spits out the value of a config var. It should be pretty simple to create, though I haven't seen anything like it yet, so perhaps it's not as easy as I think. > I found a solution, but don't like it: > The reST files can start with a shebang and an interpreter. > See http://stackoverflow.com/questions/13903691/sphinx-variables > > FYI, that SO answer is referring to sphinx-the-search-engine, not sphinx-the-documentation-system. So that really won't work. > Thomas > -- Kevin Horn -- You received this message because you are subscribed to the Google Groups "sphinx-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sphinx-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
