Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that datasette.render_template(template, ...) also accepts a list of templates #1045

Closed
simonw opened this issue Oct 23, 2020 · 1 comment

Comments

@simonw
Copy link
Owner

simonw commented Oct 23, 2020

https://docs.datasette.io/en/stable/internals.html#await-render-template-template-context-none-request-none

await .render_template(template, context=None, request=None)

This currently only accepts a single template. If it accepted a list of templates (where the first available template gets rendered) it could be more widely used by Datasette internally.

Spotted this while researching #1042.

@simonw
Copy link
Owner Author

simonw commented Oct 24, 2020

It turns out it already does that:

datasette/datasette/app.py

Lines 710 to 720 in 976e5f7

async def render_template(
self, templates, context=None, request=None, view_name=None
):
context = context or {}
if isinstance(templates, Template):
template = templates
else:
if isinstance(templates, str):
templates = [templates]
template = self.jinja_env.select_template(templates)

But the documentation doesn't reflect that:

template - string

The template file to be rendered, e.g. my_plugin.html. Datasette will search for this file first in the --template-dir= location, if it was specified - then in the plugin's bundled templates and finally in Datasette's set of default templates.

@simonw simonw changed the title datasette.render_template(template, ...) should also accept a list of templates Document that datasette.render_template(template, ...) also accepts a list of templates Oct 24, 2020
@simonw simonw added this to the 0.51 milestone Oct 24, 2020
@simonw simonw closed this as completed in 8148c9e Oct 24, 2020
simonw added a commit that referenced this issue Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant