From 189cf23c1c5d527ae97668f6f32610c81c0909b0 Mon Sep 17 00:00:00 2001 From: Darek Date: Fri, 2 Sep 2022 12:23:05 +0200 Subject: [PATCH 1/2] 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. --- docs/customization.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/customization.md b/docs/customization.md index 455f3b52c6e..430e9859297 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -170,6 +170,8 @@ 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() }}` before 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. + The following template blocks are provided by the theme: | Block name | Purpose | From 0aff4904352f8e141da80111ba70feb6a97199da Mon Sep 17 00:00:00 2001 From: Darek Date: Mon, 5 Sep 2022 10:59:52 +0200 Subject: [PATCH 2/2] suggested correction --- docs/customization.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/customization.md b/docs/customization.md index 430e9859297..b5226f70b80 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -170,7 +170,18 @@ 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() }}` before 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. +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() }} + +