Skip to content
Discussion options

You must be logged in to vote

Yes. Add the extension's template directory during config-inited, which runs before the HTML builder initializes its template loader:

from pathlib import Path

TEMPLATES = Path(__file__).with_name("_templates")

def _add_templates(app, config):
    path = str(TEMPLATES)
    if path not in config.templates_path:
        config.templates_path.append(path)

def setup(app):
    app.connect("config-inited", _add_templates)
    return {
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }

Appending is preferable to prepending: a user's own _templates directory remains earlier in the search order and can override your packaged template. Include _templates/your_widget.html

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by drewcassidy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants