diff --git a/doc/ns3_html_theme/layout.html b/doc/ns3_html_theme/layout.html
index ad2303ac0..a76af11d8 100644
--- a/doc/ns3_html_theme/layout.html
+++ b/doc/ns3_html_theme/layout.html
@@ -25,6 +25,7 @@
+
{% endblock %}
diff --git a/doc/ns3_html_theme/static/ns3_links.js b/doc/ns3_html_theme/static/ns3_links.js
index 2a656d940..0cd4e6fec 100644
--- a/doc/ns3_html_theme/static/ns3_links.js
+++ b/doc/ns3_html_theme/static/ns3_links.js
@@ -24,7 +24,14 @@ var ns3_index = "index.html";
var ns3_rel = ns3_host + ns3_release;
var ns3_api = ns3_rel + ns3_doxy + ns3_index;
-ns3_index = ns3_local + "html/" + ns3_index;
+// The Sphinx layout template defines
+// var ns3_builder = "html", or "singlehtml"
+// so we can condition the links on single/multi-page view.
+if ( (typeof ns3_builder != 'undefined') && (ns3_builder == "singlehtml") ) {
+ ns3_index = ns3_local + "singlehtml/" + ns3_index;
+ } else {
+ ns3_index = ns3_local + "html/" + ns3_index;
+ }
var ns3_man = ns3_rel + "manual/" + ns3_index;
var ns3_mod = ns3_rel + "models/" + ns3_index;