diff --git a/sphinx_rtd_theme/__init__.py b/sphinx_rtd_theme/__init__.py
index f254c4e6..75d3fa84 100644
--- a/sphinx_rtd_theme/__init__.py
+++ b/sphinx_rtd_theme/__init__.py
@@ -31,6 +31,9 @@ def config_initiated(app, config):
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
)
+def page_context_handler(app, pagename, templatename, context, doctree):
+ """Expose sphinx version to html templates in a more programatic way."""
+ context['sphinx_version_tuple'] = sphinx_version
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
def setup(app):
@@ -61,4 +64,6 @@ def setup(app):
else:
app.config.html_add_permalinks = "\uf0c1"
+ app.connect('html-page-context', page_context_handler)
+
return {'parallel_read_safe': True, 'parallel_write_safe': True}
diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html
index dcee8308..bc821a57 100644
--- a/sphinx_rtd_theme/layout.html
+++ b/sphinx_rtd_theme/layout.html
@@ -20,7 +20,7 @@
{%- endblock -%}
{#- CSS #}
- {%- if (sphinx_version < "4.0.0") -%}
+ {%- if sphinx_version_tuple < (4, 0,) -%}
{%- endif %}
@@ -58,8 +58,8 @@
{%- if not embedded %}
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
- {%- if sphinx_version >= "1.8.0" -%}
- {%- if sphinx_version < "4.0.0" -%}
+ {%- if sphinx_version_tuple >= (1, 8) -%}
+ {%- if sphinx_version_tuple < (4, 0) -%}
{%- endif -%}
{%- for scriptfile in script_files %}