Skip to content

Commit 54d0a99

Browse files
authored
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
1 parent 1a9bc1d commit 54d0a99

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/customization.md

+13
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ Then, e.g. to override the site title, add the following lines to `main.html`:
170170
{% endblock %}
171171
```
172172

173+
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`:
174+
175+
```html
176+
{% extends "base.html" %}
177+
178+
{% block scripts %}
179+
180+
{{ super() }}
181+
182+
<script id="snippet" src="https://widgets.example.com/snippet.js> </script>
183+
184+
{% endblock %}
185+
173186
The following template blocks are provided by the theme:
174187
175188
| Block name | Purpose |

0 commit comments

Comments
 (0)