question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Utility mechanism for plugins to render templates

See original GitHub issue

Sometimes a plugin will need to render a template for some custom UI. We need a documented API for doing this, which ensures that everything will work correctly if you extend base.html etc.

See also #576. This could be a .render() method on the Datasette class, but that feels a bit weird - should that class also take responsibility for rendering?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
simonwcommented, Feb 4, 2020

For the moment I’m going to move it to async def render_template() on datasette but otherwise keep the implementation the same.

The new signature will be:

async def render_template(self, template, context=None, request=None, view_name=None):

template can be a list of strings or a single string. If a list of strings a template will be selected from them.

I’ll reconsider the large list of default context variables later on in a separate ticket.

0reactions
simonwcommented, Dec 22, 2019

The code in question currently lives in BaseView.render():

https://github.com/simonw/datasette/blob/d54318fc7f2565e6121920ce1ea9cb8b700e629a/datasette/views/base.py#L106-L163

Should datasette.render_template() do exactly this, or should it be slightly different?

Plugins need the option to not pass a request object - so maybe that parameter becomes optional.

Perhaps plugins should be able to render templates without other plugins getting to inject their own variables?

Does it always make sense to dump in all of those extra template context variables?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins — Airflow Documentation
A web server you can use to render your views. A metadata database to store your models. Access to your databases, and knowledge...
Read more >
The only Figma plugins you need for your workflow - UX Planet
The plugin offers different chart templates with great visual styling. It can generate random data with different distribution types as per your ...
Read more >
Connect your theme to plugin-outlets to inject templates with ...
When injecting HTML into your page you can also inject templates, this gives you a very simple mechanism for injecting content into various...
Read more >
Plugins — CrafterCMS 4.0.2 documentation
CrafterCMS provides a mechanism (a “hook”) for adding markup and defining macros for plugins via Freemarker templates. These templates, when the plugin has ......
Read more >
dev Plugin - DokuWiki
This command line plugin helps plugin and template developers dealing with the boilerplate required. It can be used to create and extend ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found