sections: plugin_hooks:plugin-hook-prepare-jinja2-environment
This data as json
id | page | ref | title | content | breadcrumbs | references |
---|---|---|---|---|---|---|
plugin_hooks:plugin-hook-prepare-jinja2-environment | plugin_hooks | plugin-hook-prepare-jinja2-environment | prepare_jinja2_environment(env, datasette) | env - jinja2 Environment The template environment that is being prepared datasette - Datasette class You can use this to access plugin configuration options via datasette.plugin_config(your_plugin_name) This hook is called with the Jinja2 environment that is used to evaluate Datasette HTML templates. You can use it to do things like register custom template filters , for example: from datasette import hookimpl @hookimpl def prepare_jinja2_environment(env): env.filters["uppercase"] = lambda u: u.upper() You can now use this filter in your custom templates like so: Table name: {{ table|uppercase }} This function can return an awaitable function if it needs to run any async code. Examples: datasette-edit-templates | ["Plugin hooks"] | [{"href": "http://jinja.pocoo.org/docs/2.10/api/#custom-filters", "label": "register custom\n template filters"}, {"href": "https://datasette.io/plugins/datasette-edit-templates", "label": "datasette-edit-templates"}] |