Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using {{ super() }} for extending a block #4309

Merged
merged 2 commits into from Sep 11, 2022

Conversation

Vegebutcher
Copy link
Contributor

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.

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.
@squidfunk
Copy link
Owner

Thanks for the PR! Shouldn't it be after the block statement, so that it's in the block?

@Vegebutcher
Copy link
Contributor Author

Thanks for the PR! Shouldn't it be after the block statement, so that it's in the block?

I'm not sure. It works for us when it's before block. But it can be at the end as well. Both ways are presented here.

@squidfunk
Copy link
Owner

I'm not sure we're talking about the same thing. Please provide an example for clarification.

@Vegebutcher
Copy link
Contributor Author

Vegebutcher commented Sep 2, 2022

OK, so this is how we implemented the Zendesk widget:

{% extends "base.html" %}

{% block scripts %}

{{ super() }}
<!-- Start of xorlab Zendesk Widget script -->
<script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key=xxxxxxxxxxx"> </script>
<!-- End of xorlab Zendesk Widget script -->

{% endblock %}

Now I got your point: I meant the new content in a block, but wrote about a block statement. My bad. Yes, this super function should be invoked inside the block, but I am not sure if it really matters if it's before or after the new content.

@squidfunk
Copy link
Owner

Thanks! Yes, it matters. The content of the block is expanded where the super call is located, so order definitely matters.

docs/customization.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Vegebutcher Vegebutcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction to instructions

docs/customization.md Outdated Show resolved Hide resolved
@squidfunk
Copy link
Owner

Thanks! LGTM. I might adjust the formatting a little.

@squidfunk squidfunk merged commit 54d0a99 into squidfunk:master Sep 11, 2022
@Vegebutcher Vegebutcher deleted the patch-2 branch September 21, 2022 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants