-
Hi ! I am currently looking for a way to show an announcement bar only when I build the documentation for a branch different than Option °1:I was wondering if there is a way to do something like this in the {% extends "base.html" %}
{% set DOC_BRANCH = os.environ.get('CI_COMMIT_BRANCH', False) %}
{% if DOC_BRANCH != "master" %}
{% block announce -%}
Be careful, you are currently reading the documentation for a branch under development: {{ DOC_BRANCH }}.
{%- endblock %}
{% endif %} I think of course I can't use python syntax in jinja2 files, and tutos I found on internet say to add a Option °2:I also find this Q&A discussion Versioning - Pre-Release Banner #5803 which seems not bad for what I want to do, I just have to replace the value in the
... when I use this ...
Do you know if a thing like this can be done easily, or why I got this error when I try the second option? Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Thanks for asking. #5803 was also immediately coming to my mind. You can use environment variables in MkDocs, so something like this should work, setting the branch name to extra:
branch: !ENV [BRANCH, "master"] And then call MkDocs like so: BRANCH=`git branch --show-current` mkdocs build In your override: {% if config.extra.branch != "master" %}
{% block announce -%}
Be careful, you are currently reading the documentation for a branch under development: {{ config.extra.branch }}.
{%- endblock %}
{% endif %} |
Beta Was this translation helpful? Give feedback.
Thanks for asking. #5803 was also immediately coming to my mind. You can use environment variables in MkDocs, so something like this should work, setting the branch name to
master
by default:And then call MkDocs like so:
BRANCH=`git branch --show-current` mkdocs build
In your override: