diff --git a/doc/_templates/layout.html b/doc/_templates/layout.html
index 062be3b551db..2da65d8fd8e8 100644
--- a/doc/_templates/layout.html
+++ b/doc/_templates/layout.html
@@ -76,19 +76,27 @@
{{ _('Navigation') }}
{%- endmacro %}
{%- macro script() %}
-
- {%- for scriptfile in script_files %}
-
- {%- endfor %}
+ {% if sphinx_version >= "1.8.0" %}
+
+ {%- for scriptfile in script_files %}
+ {{ js_tag(scriptfile) }}
+ {%- endfor %}
+ {% else %}
+
+ {%- for scriptfile in script_files %}
+
+ {%- endfor %}
+ {% endif %}
{%- endmacro %}
{%- macro css() %}