moving the "quick search" field above the table of contents in the sidebar

51 views
Skip to first unread message

Bob DuCharme

unread,
Sep 12, 2019, 9:56:46 AM9/12/19
to sphinx-users
Can someone tell me how to move the "quick search" field from underneath the table of contents in the sidebar to above the table of contents?

Here's what I tried: in my conf.py I have templates_path = [`_templates`]. I copied sphinx/themes/basic/layout.html into source/_templates, and when I add test strings to that template file I see some of them show up in the rendered version, so I know that I have it in the right place to override its contents. But, I don't see any of the test strings that I put near the sidebarsearch block in that file showing up in the rendered version, so I don't think that grabbing that sidebarsearch block and moving it somewhere else will help. I also tried putting a copy of theme.conf into source/_templates and moving searchbox.html to the beginning of the sidebars list in that file, but that had no effect. 

I wondered if I was even trying to override the right file to do this. Any suggestions?

Thanks,

Bob

Stefano David

unread,
Sep 13, 2019, 2:49:24 AM9/13/19
to sphinx-users
Hello Bob,


On Thursday, 12 September 2019 15:56:46 UTC+2, Bob DuCharme wrote:

I wondered if I was even trying to override the right file to do this. Any suggestions?
Can you tell which blocks are you trying to move?
Inside layout.html If I put the block
{% include "searchbox.html" %}
at the end or beginning of the

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          {% block menu %}

block, I can successfully see the search field moving above or below the navigation.

I am using rtd theme, with few slight changes to the template (none to layout.htm, though), but I have a ./theme directory within my source folder which includes the various html templates.

HTH,
Stefano

Thanks,

Bob

Bob DuCharme

unread,
Sep 13, 2019, 11:52:55 AM9/13/19
to sphinx-users
Thanks Stefano, that worked! I'm using the alabaster theme, moved the sidebarsearch block, and that worked. (Just having layout.html in source/_templates also added navigation links at the top and bottom of the screen, but I eventually figured out that commenting out the relbar1 and relbar2 blocks made them go away.)

I usually get to know these templates by adding <span>flag1</span>, <span>flag2</span>, etc. in various places to see where they show up, and because those weren't all behaving the way I expected I thought I was misunderstanding something more fundamental about the template, but now I have the search box where I want it. 

Thanks,

Bob

Stefano David

unread,
Sep 16, 2019, 9:02:28 AM9/16/19
to sphinx-users
Hi Bob,


On Friday, 13 September 2019 17:52:55 UTC+2, Bob DuCharme wrote:
Thanks Stefano, that worked! I'm using the alabaster theme, moved the sidebarsearch block, and that worked. (Just having layout.html in source/_templates also added navigation links at the top and bottom of the screen, but I eventually figured out that commenting out the relbar1 and relbar2 blocks made them go away.)
Glad to hear that it worked!
 
I usually get to know these templates by adding <span>flag1</span>, <span>flag2</span>, etc. in various places to see where they show up, and because those weren't all behaving the way I expected I thought I was misunderstanding something more fundamental about the template, but now I have the search box where I want it. 
Well, it is not that difficult to read these templates and understand what goes where :-) but if you need to add some foo content just to check, I'd suggest to use <div>s rather than <span>, becuase they are more evident and easier spottable on the resulting HTML (also, adding some CSS to highlight them may help in debugging).

Best regards,
Stefano
 
Reply all
Reply to author
Forward
0 new messages