{"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715643763", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715643763, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTY0Mzc2Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-24T00:34:31Z", "updated_at": "2020-10-24T00:34:52Z", "author_association": "OWNER", "body": "I'm going to rename that to template variable from `select_templates` to `templates_considered` too.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715643646", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715643646, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTY0MzY0Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-24T00:33:46Z", "updated_at": "2020-10-24T00:33:46Z", "author_association": "OWNER", "body": "I'd like to do this all in the `datasette.render_template()` method to ensure it's available to plugins as well, not just core code that uses the `BaseView` class.\r\n\r\nThis code is the problem:\r\nhttps://github.com/simonw/datasette/blob/d3e9b0aecb6f8e9b2befd9c654ccb7ce852db3e7/datasette/views/base.py#L114-L133\r\n\r\nI think I'll fix this by moving the `select_templates` mechanism into `datasette.render_templates()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715618333", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715618333, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxODMzMw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:33:24Z", "updated_at": "2020-10-23T22:33:24Z", "author_association": "OWNER", "body": "It wouldn't be a disaster if template-loading plugins were unable to hook into the `/{slug1}/{slug2}.html` custom page mechanism, since plugins can define their own pages already using `register_routes()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715618077", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715618077, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxODA3Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:32:24Z", "updated_at": "2020-10-23T22:32:24Z", "author_association": "OWNER", "body": "Another option: the first version of the plugin hook could accept only the template filename. Subsequent releases could add more arguments, since Pluggy allows new arguments to be added without breaking backwards compatibility.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715617830", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715617830, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxNzgzMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:31:26Z", "updated_at": "2020-10-23T22:31:26Z", "author_association": "OWNER", "body": "So maybe this should be a `register_template_loader` mechanism that returns a Jinja loader after all? That would mean that only the template filename could be used as the input to the plugin, which doesn't seem as useful as emulating the `extra_template_vars()` interface.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715617405", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715617405, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxNzQwNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:29:53Z", "updated_at": "2020-10-23T22:29:53Z", "author_association": "OWNER", "body": "Also consider that `DatasetteRouter` uses `.list_templates()` to gather together `{slug}.html` style templates for the custom page templates mechanism: https://github.com/simonw/datasette/blob/976e5f74aae1fa0d406df6691dc8b5feeebe8788/datasette/app.py#L949-L967\r\n\r\nFor that to work with the new plugin hook, custom template providing plugins will need a way to provide a list of templates that they know about.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715616757", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715616757, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxNjc1Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:27:28Z", "updated_at": "2020-10-23T22:27:28Z", "author_association": "OWNER", "body": "Almost all of the core template loading happens in the `BaseView.render` method: https://github.com/simonw/datasette/blob/976e5f74aae1fa0d406df6691dc8b5feeebe8788/datasette/views/base.py#L114-L133\r\n\r\nThe one exception is the 404 handling code here: https://github.com/simonw/datasette/blob/976e5f74aae1fa0d406df6691dc8b5feeebe8788/datasette/app.py#L1034-L1042", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715614971", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715614971, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTYxNDk3MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T22:20:14Z", "updated_at": "2020-10-23T22:23:51Z", "author_association": "OWNER", "body": "Alternative plugin hook idea:\r\n```python\r\n@hookspec\r\ndef load_template(template, database, table, columns, view_name, request, datasette):\r\n \"Load the specified template, returning the template code as a string\"\r\n```\r\nImitating the existing `extra_template_vars` family of hooks: https://docs.datasette.io/en/stable/plugin_hooks.html#extra-template-vars-template-database-table-columns-view-name-request-datasette", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715497419", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715497419, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTQ5NzQxOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T18:12:40Z", "updated_at": "2020-10-23T18:12:40Z", "author_association": "OWNER", "body": "Maybe the template loader can optionally return some extra context to pass to the template. That could be used to solve the templates considered comment.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715496859", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715496859, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTQ5Njg1OQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T18:11:27Z", "updated_at": "2020-10-23T18:11:27Z", "author_association": "OWNER", "body": "When loading a template the filename is required, but you can optionally also send a set of extra arguments which the template loader can take into consideration.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-715490532", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 715490532, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNTQ5MDUzMg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T17:57:34Z", "updated_at": "2020-10-23T17:57:34Z", "author_association": "OWNER", "body": "A better version of this hook would be passed the database, table and query name depending on what was being rendered.\r\n\r\nThis would require some re-thinking of how core templates are loaded, especially since I would want the templates considered comment to continue working.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-714868867", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 714868867, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNDg2ODg2Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T02:31:17Z", "updated_at": "2020-10-23T02:31:17Z", "author_association": "OWNER", "body": "I'll build this in conjunction with a plugin that supports editing templates stored in SQLite.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-714868624", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 714868624, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNDg2ODYyNA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T02:30:27Z", "updated_at": "2020-10-23T02:30:37Z", "author_association": "OWNER", "body": "Maybe `register_template_loader(datasette)` which returns an object which is added in at the beginning of the list passed to `ChoiceLoader` here.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1042#issuecomment-714868207", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1042", "id": 714868207, "node_id": "MDEyOklzc3VlQ29tbWVudDcxNDg2ODIwNw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-23T02:29:12Z", "updated_at": "2020-10-23T02:29:12Z", "author_association": "OWNER", "body": "Relevant code: https://github.com/simonw/datasette/blob/d0cc6f4c32e1f89238ddec782086b3122f445bd4/datasette/app.py#L288-L311", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 727802081, "label": "Plugin hook for loading templates"}, "performed_via_github_app": null}