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
Ability for plugins to collaborate when adding extra HTML to blocks in default templates #1191
Comments
This relates to #987 (documented HTML hooks for JavaScript plugins) but is not quite the same thing. |
Also related: #857 (comprehensive documentation of variables available to templates) - since then the plugin hook could be fed the full template context and use that to do its thing. Or maybe the plugin hooks gets to return the name of a template that should be |
Plugins that want to provide extra context to the template can already do so using the So this hook could work by returning a list of template filenames to be included. Those templates can be bundled with the plugin. Since they are included they will have access to the template context and to any |
I think this ends up being a whole collection of new plugin hooks, something like:
|
I'm going to prototype this in a branch. |
I'm going to try using Jinja macros to implement this: https://jinja.palletsprojects.com/en/2.11.x/templates/#macros Maybe using one of these tricks to auto-load the macro? http://codyaray.com/2015/05/auto-load-jinja2-macros |
Another potential use for this: plugins that provide authentication (like |
I can combine this with #987 - each of these areas of the page can be wrapped in a |
I've got a good prototype working now, but I'm dropping this from the Datasette 0.54 milestone because it requires a bunch of additional work to make sure it is really well tested and documented. |
More work can happen in the PR: #1204 |
I've got a URL shortening plugin that I would like to embed on the query page but I'd like avoid capturing the entire |
One note here: this feature could be called "slots", similar to Layout Slots in Vitepress. In Vitepress, you can add custom components/widget/gadgets into determined named "slots", like so:
Would be great to do in both Python and Javascript, with the upcoming JavaScript API #2052. In |
Thinking about this again. I think it only needs the top slots for the moment (I do like the term slots). So maybe:
I'm not sure the word
|
Originally I thought about having some kind of accompanying template mechanism where you can have a template called |
i should probably distinguish between the canned query results page, the database index page and the |
OK, I have a working prototype of the Here's a plugin that uses a from datasette import hookimpl
import jinja2
@hookimpl
def top_homepage(datasette, request):
async def inner():
try:
return await datasette.render_template("top_homepage.html", request=request)
except jinja2.exceptions.TemplatesNotFound:
return None
return inner |
Moving development to this PR: |
Preview of the documentation, showing all of the planned hooks: https://datasette--2238.org.readthedocs.build/en/2238/plugin_hooks.html#top-homepage-datasette-request |
I'm going to go with |
Better documentation: https://datasette--2238.org.readthedocs.build/en/2238/plugin_hooks.html#template-slots |
Sometimes a plugin may want to add content to an existing default template - for example
datasette-search-all
adds a new search box at the top ofindex.html
. I also wantdatasette-upload-csvs
to add a CTA on thedatabase.html
page: simonw/datasette-upload-csvs#18Currently plugins can do this by providing a new version of the
index.html
template - but if multiple plugins try to do that only one of them will succeed.It would be better if there were known areas of those templates which plugins could add additional content to, such that multiple plugins can use the same spot.
The text was updated successfully, but these errors were encountered: