sphinx-contrib/datatemplates

Where should be put template files?

kevung opened this issue · 5 comments

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

  • an RST file test.rst
.. datatemplate:json:: test.json
   :template: ./test.tmpl
  • a JSON file test.json
{
   "allo": "test"
}

  • 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,

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!

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.

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

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.

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