diff --git a/datasette/app.py b/datasette/app.py index 5973b3cd..3067b60f 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -45,10 +45,16 @@ connections = threading.local() class RenderMixin(HTTPMethodView): def render(self, templates, **context): + template = self.jinja_env.select_template(templates) + select_templates = ['{}{}'.format( + '*' if template_name == template.name else '', + template_name + ) for template_name in templates] return response.html( - self.jinja_env.select_template(templates).render({ + template.render({ **context, **{ 'app_css_hash': self.ds.app_css_hash(), + 'select_templates': select_templates, } }) ) diff --git a/datasette/templates/base.html b/datasette/templates/base.html index 159d0f91..6da5ee46 100644 --- a/datasette/templates/base.html +++ b/datasette/templates/base.html @@ -33,6 +33,6 @@ {% endif %}{{ metadata.source or metadata.source_url }}{% if metadata.source_url %}{% endif %} {% endif %} - +{% if select_templates %}{% endif %} diff --git a/docs/custom_templates.rst b/docs/custom_templates.rst index 20c2a0bd..0eae5966 100644 --- a/docs/custom_templates.rst +++ b/docs/custom_templates.rst @@ -143,6 +143,18 @@ templates:: table-mydatabase-Food-Trucks-399138.html table.html +You can find out which templates were considered for a specific page by viewing +source on that page and looking for an HTML comment at the bottom. The comment +will look something like this:: + + + +This example is from the canned query page for a query called "tz" in the +database called "mydb". The asterisk shows which template was selected - so in +this case, Datasette found a template file called ``query-mydb-tz.html`` and +used that - but if that template had not been found, it would have tried for +``query-mydb.html`` or the default ``query.html``. + It is possible to extend the default templates using Jinja template inheritance. If you want to customize EVERY row template with some additional content you can do so by creating a ``row.html`` template like this::