From 54d0a992b7f27453f4a4b12b58e7b33cc8cf4b46 Mon Sep 17 00:00:00 2001 From: Darek Date: Sun, 11 Sep 2022 16:44:06 +0200 Subject: [PATCH] Using `{{ super() }}` for extending a block (#4309) * Using `{{ super() }}` for extending a block Yesterday we were struggling with adding a Zendesk widget (a simple JS) to our docs, because overriding any existing template block would lead to a broken site. Finally, we found this function which saved us. I wanted to share this, because it's not a common knowledge and it might be helpful for others. * suggested correction --- docs/customization.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/customization.md b/docs/customization.md index 455f3b52c..b5226f70b 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -170,6 +170,19 @@ Then, e.g. to override the site title, add the following lines to `main.html`: {% endblock %} ``` +If you intend to add some code to a block rather than to replace it altogether with new content, use `{{ super() }}` right after the `{% block %}` statement to include the original block content. This is particularly useful when adding some third-party widgets to your docs, e.g., for chatting with support or submitting a ticket. For example, if your widget script is hosted on `widgets.example.com`, add the following lines to `main.html`: + +```html +{% extends "base.html" %} + +{% block scripts %} + +{{ super() }} + +