pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
600 stars 313 forks source link

extend theme for specific page #1725

Closed banson-aiq closed 7 months ago

banson-aiq commented 7 months ago

I suspect this is likely me missing something, so hopefully someone can help me find the problem. After looking through the sphinx documentation I believe I should be able to extend the layout.html in pydata-sphinx-theme for a specific page using some jinja2 expressions. However no matter what I try I can't get the index.rst page to use the extended layout. Here is what I have setup...

doc/source/conf.py snippet

templates_path = ['_templates']
html_theme = 'pydata_sphinx_theme'

doc/source/index.rst the page I want to use the extended layout

:page_template: layout-main
.. _docs_mainpage:

############
documentation
############

Some content

doc/source/_templates/layout-main.html the extended layout template

{% extends "!layout.html" %}

{% block content %}
  Test block
{% endblock content %}
drammock commented 7 months ago

I don't think :page_template: is valid sphinx file-wide metadata? I've never seen it, and searching for page_template in sphinx docs and source code doesn't turn up anything. I can get expected results if I change the filename from layout-main.html to just layout.html (still in the _templates folder)... but that's going to affect all pages. The way I've handled page-specific templates in my own projects is to use jinja conditionals:

https://github.com/mne-tools/mne-python/blob/69d29637db82563cd56d8effc396124f243cf4fb/doc/_templates/layout.html#L11-L13

closing as "not planned" but feel free to re-open / ask clarifying questions if this doesn't solve your problem!

banson-aiq commented 7 months ago

Thanks for looking into it. I ended up using jinja conditionals