How do I use config values ​​in templates?

I set the config value to big_logo with a simple extension . I also tested my way of setting config values ​​using sphinx.ext.ifconfig and it seems to work.

Now I would like to use this in a template for layout.html like this:

{% extends "!layout.html" %}
{% block header %}
    {%- if big_logo %}
       <div style="background-color: white;>
           <img src="{{ pathto("_static/" + big_logo, 1) }}" alt="logo" />
    {% endif %}
{% endblock %}


It doesn't work, however; make html gives:

Exception occurred:
File "...", line 7, in block "header"
   <img src="{{ pathto("_static/" + big_logo, 1) }}" alt="logo" />
UndefinedError: 'big_logo' is undefined


This is similar to the layout.html of the main theme:

{%- block sidebarlogo %}
  {%- if logo %}
   <p class="logo"><a href="{{ pathto(master_doc) }}">
          <img class="logo" src="{{ pathto('_static/' + logo, 1) }}" alt="Logo"/>


My only doubt is that does not set the variable "logo" but "html_logo".

Any ideas on how to use config values ​​in templates?


source to share

1 answer

You want to pass the configuration value to the html context parameter . In my opinion, only the variables defined by Sphinx will be available in templates , and the variables in this dictionary. I'm not sure exactly how this will interact with the way you set up the config variable, assuming you want to do it as you describe in your other question , but it should be efficient. Just remember that the file

is just regular Python.



All Articles