Reputation: 115
Some static files from a sphinx template package appear under /some/path/_static
when my root doc is at /some/path/index.html
. In my template I want to reference files in the _static
folder.
Currently I use src="{{ pathto(master_doc)[:-10] }}_static/...
which looks hacky and only work as long as the root file has a name of the correct length.
Alternatively, I tried src="{{ pathto(master_doc)}}/../_static/
. This breaks for index.html itself.
Is there a way to get the path of the folder the master_doc
is in?
Upvotes: 1
Views: 1246
Reputation: 15105
To reference a file in Sphinx's static directory from a template, use pathto(file, 1)
.
This returns the path to a file which is a filename relative to the root of the generated output. Use this to refer to static files.
For an image, you would use this in the template.
src="{{ pathto('_static/my-file.jpg', 1) }}
Upvotes: 3