sphinx-contrib / datatemplates

Sphinx plugin for generating RST on the fly from data files and templates.
http://sphinxcontribdatatemplates.readthedocs.io/
Other
44 stars 19 forks source link

Where should be put template files? #76

Closed kevung closed 3 years ago

kevung commented 3 years ago

Trying to debug #75 , I have created a simple example with in the same folder

- a template `test.tmpl`

Test



{{ data['allo'] }}

```
I get this error in the log when building Sphinx
```
    raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: ./test.tmpl
```

This indicates jinja2 does not find the template. Where should the template be put? This point is not mentionned in the doc.

Thanks in advance,
dhellmann commented 3 years ago

Template files should be in one of the directories in the templates_path configuration setting. See https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-templates_path for details.

I have proposed an update to the documentation in #77 to explain this.

Thanks for pointing out the gap in our documentation!

kevung commented 3 years ago

Hi @dhellmann , Thank you so much for your quick and precise answer. I confirm that your indications are sufficient and I successfully could test your extension (by creating the sphinx template folder and adding to the templates_path variable). I think I can close this issue. Thanks again and take care.

ghost commented 9 months ago

I am sorry to come back to this issue, but I don't get it. Should I put the absolute template path in template_paths?

My config.py:

project = "Test"
extensions = ['myst_parser','sphinxcontrib.datatemplates']
templates_path = ['./templates']
html_theme = "sphinxdoc"

The template is called like this:

.. datatemplate:json:: status.json
   :template: status.tmpl

My project looks like this:

documentation/
├── README.rst
├── docs
│   ├── Makefile
│   ├── build
│   ├── make.bat
│   └── source
└── templates
    └── status.tmpl
dhellmann commented 9 months ago

According to the template_path docs:

Relative paths are taken as relative to the configuration directory.

So, you need to move your templates directory to the same place as your conf.py file.

ghost commented 8 months ago

Thank you for the answer. I did not get that the configuration directory is where conf.py is.