jeremywat
jeremywat

Reputation: 1045

MkDocs not seeing extra_templates?

I'm getting started using MkDocs. I've defined a custom template at docs/templates/my_template.html. I've specified the template in mkdocs.yml according to this documentation:

extra_templates:
  - templates/my_template.html

In the document meta-data/front matter, I've specified the template to use according to this documentation:

---
template: my_template.html
---

When I run mkdocs build I get this error:

jinja2.exceptions.TemplateNotFound: 'my_template.html' not found in search paths: '/usr/local/lib/python3.13/site-packages/material/templates', '/usr/local/lib/python3.13/site-packages/mkdocs/templates'

Inside the document meta-data I've tried a number of different combinations of the template: my_template, my_template.html, templates/my_template, templates/my_template.html. Nothing is working.

If it helps, I'm using the Material theme.

Why is MKDocs not able to see the template file, even though I specified that folder under extra_templates? How do I get this working?

Upvotes: 0

Views: 43

Answers (1)

jeremywat
jeremywat

Reputation: 1045

According to this documentation, templates can also be defined under custom_dir (relative to the root directory--not the docs_dir) in the theme like this:

theme:
  name: material
  custom_dir: templates/

I'm still not sure what extra_templates is for, but once I configured theme:custom_dir it worked.

Upvotes: 0

Related Questions