sphinx-bootstrap-theme icon indicating copy to clipboard operation
sphinx-bootstrap-theme copied to clipboard

[Info] Change template for index.html

Open himito opened this issue 8 years ago • 4 comments

Hello,

I would like to change the template only for the index.html. There is a way to do that ?

Thank you in advance !

himito avatar Mar 22 '17 13:03 himito

Not sure offhand -- that's more of a "sphinx" general thing than a "sphinx bootstrap theme" thing. Perhaps the official sphinx docs can help you?

ryan-roemer avatar Mar 22 '17 20:03 ryan-roemer

Thank you for your help !

himito avatar Mar 22 '17 22:03 himito

This can be be done by adding a layout.html file to your _templates directory that extends the bootstrap file. I was able to modify the template, only for the index.html, by adding the following

{% if pagename == "index" %}
  <your HTML goes here>
{% endif %}

Here is all my code. My goal was to add a banner image and title so I created variable in conf.py using the html_context dictionary

{% extends "!layout.html" %}

{%- block content %}
{{ navBar() }}
{% if pagename == "index" and show_banner %}
  <div class="container-fluid text-center">
    <h1>{{ banner_title }}</h1>
    <img src="{{ pathto('_static/' + banner_image, 1) }}">
  </div>
{% endif %}
<div class="container">
  <div class="row">
    {%- block sidebar1 %}{{ bsidebar() }}{% endblock %}
    <div class="{{ bs_span_prefix }}{{ bs_content_width }} content">
      {% block body %}{% endblock %}
    </div>
    {% block sidebar2 %} {# possible location for sidebar #} {% endblock %}
  </div>
</div>
{%- endblock %}

iwelch82 avatar Apr 05 '18 22:04 iwelch82

Thank you!

himito avatar Nov 01 '19 21:11 himito