How do I include a custom jinja2 html file into the Bokeh server embed sample program ?
See:
https://github.com/bokeh/bokeh/blob/0.13.0/examples/howto/server_embed/standalone_embed.py
Having an html file in templates/index.html does not load by default like it does with the directory format Bokeh server.
Add to the server embed example file:
from jinja2 import Template
and in the modify_document function add:
with open('./path/to/my.html') as f:
index_template = Template(f.read())
doc.template = index_template
This works because the document object has a template attribute
and bokeh seems to render that for us.
Also include the bokeh variables in the jinja2 template:
<head>
{{ bokeh_css }}
{{ bokeh_js }}
</head>
and the body should have:
<body>
{{ plot_div|indent(8) }}
{{ plot_script|indent(8) }}
</body>
Related
I'm having some issues adding a custom footer to my Sphinx .html files. I'm using the sphinx_rtd_theme. I've checked this post and tried it (and some of the suggestions in the comments) but to no avail. I'm not sure what I'm missing. Apologies if I haven't posted enough here to actually indicate what is causing the problem. Any help or suggestions is appreciated!
My css theme file has been (poorly) modified by myself (I'm not an HTML/CSS person!) but I don't think that should matter? The only other thing I can think of is maybe I have to do something special when I re-compile the output files. I just use:
make clean html && make html
My conf.py is located at: root/source/conf.py. Here's some excerpts from my conf.py file:
import sphinx_rtd_theme
project = 'Project Name'
copyright = '2021, My Company'
author = 'My Name, Coworker Name'
master_doc = 'Home'
extensions = ["sphinx_rtd_theme", "sphinx.ext.todo"]
todo_include_todos = True
templates_path = ['_templates']
source_suffix = ['.rst']
html4_writer = True
html_theme = 'sphinx_rtd_theme'
# html_theme_path = ['_static']
html_static_path = ['_static']
# html_extra_path = []
html_show_sphinx = True
html_show_copyright = True
html_style = 'css/my_theme.css'
Here's my layout.html file that I have overridden. It's located in the path shown in the comment.
<!-- layout.html
* Place this file in root/source/_templates
* -->
{% extends "!layout.html" %}
{% block extrahead %}
{{super}}
<link href="{{ pathto("_static/my_theme.css", True) }}" rel="stylesheet" type="text/css">
{% endblock %}
{% block extrafooter %}
{{super}}
<div class="footer">
My custom footer just needs to add a single sentance to the existing footer.
</div>
{% endblock %}
Do you want to add a custom footer or replace the default one? in my case, I only need to override the footer.html file instead of layout.html.
Here's what I do that 100% worked for my Sphinx documentation:
create a footer.html in the _template folder of your Sphinx project.
then add this:
{% extends "!footer.html" %}
{%- block contentinfo %}
{{ super }}
<!-- your custom footer here-->
{% endblock %}
be mindful in which block your footer is actually contained within. In my case it's inside contentinfo
So I found a workaround.
1. Copy existing RTD html files
I copied the existing RTD .html files from my virtual environment folder. On my system it was located at the usual place:
.../Miniconda3/envs/my_env_name/Lib/site-packages/sphinx_rtd_theme/
I found the following files:
breadcrumbs.html
footer.html
Layout.html
search.html
searchbox.html
theme.conf
versions.html
I copied those to my working directory for my project:
.../Documentation-repo/Sphinx/root/source/_templates/
2. Edit conf.py file in working directory
I opened my conf.py file and changed the following:
# Add any paths that contain templates here, relative to this directory.
# Uncomment the line below to enable customized template #
#
# templates_path = ['_templates']
to this:
# Add any paths that contain templates here, relative to this directory.
# Uncomment the line below to enable customized template #
#
templates_path = ['_templates']
3. Add new content to footer.html file
I opened footer.html and edited it to add the content I wanted at the bottom. In my case it was as simple as adding my single sentence of changes below the {%- block extrafooter %} {% endblock %} line. Easy. Might not be the perfect solution but it works for what I need.
I have a Jekyll site with an include file. Within that include file I am trying to include another file:
<div class="api-doc api-off api-definition" id="debugging">{% include_relative _apiDocs/debugging.md %}</div>
but this displays the markdown as a string:
--- title: API Reference | Debugging --- #### Debugging Turn on debugging: ```Javascript pbjs.setConfig({ debug: true }); ```
Is there a way to get this to render as HTML?
If you're using Kramdown as your processor, you can handle this by adding the markdown="1" attribute to the parent div:
<div class="api-doc api-off api-definition" id="debugging" markdown="1">{% include_relative _apiDocs/debugging.md %}</div>
If not, you can apply a filter on the included Markdown to convert it to HTML (see the Jekyll docs on the markdownify filter):
{%- capture debugging-doc -%}{% include_relative _apiDocs/debugging.md %}{%- endcapture -%}
<div class="api-doc api-off api-definition" id="debugging">{{ debugging-doc | markdownify }}</div>
I wanna include some HTML file on post!
I wanna show a reference on the right side of my blog.
Reference is HTML file, and it looks like simple doc.
So I created the layout file jekyll.html and I wrote a tag <div>.
Then I added a header variable to my post and reference file is located on _layouts.
This is the code in jekyll.html:
<div class="right">
{% for ref in page.refs %}
{% include ref %}
{% endfor %}
</div>
And this code post's YAML header.
---
layout: jekyll
title: "02. "
date: 2018-12-30 14:38:42 +0900
category: Jekyll
refs: [ bundler.html, test.html ]
---
So, Liquid says:
Liquid Exception: Could not locate the included file 'ref' in any of ["E:/Projects/Jekyll/_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source. in /_layouts/jekyll.html
What's wrong? Did I do anything wrong?
Or is there another way?
If you want to use a liquid variable in an include tag, you must surround it with curly braces :
{% include {{ ref }} %}
I'm extending the basic theme from sphinx-doc and I notice the following code chunk inside basic theme layout.html script macro
{%- for scriptfile in script_files %}
<script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script>
{%- endfor %}
Does that mean I can add a html_theme_options like the following inside my theme.conf:
[options]
script_files =
and inside my conf.py, I add:
html_theme_options = {'script_files': '_static'}
However, with this set, the build is totally messed up and produced junk pages like:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>...</head>
<body>
-->
<!-- my js code but is automatically commented out-->
</body>
</html>
Which part goes wrong? What should I do in order to load my own customized javascript? Thanks much!
script_files is a template-internal variable. You cannot set it via html_theme_options (all theme variables have theme_as a prefix, see below).
The Sphinx docs explain here how to add additional scripts directly in the template files, via the script_files variable.
In case you regard it as important to define the additional scripts in your conf.py, proceed as follows:
Add the following line to your template's layout.html, for example below the endblock of the DOCTYPE definition:
{% set script_files = script_files + theme_extra_scripts %}
Define the theme variable extra_scripts and its default value in theme.conf:
extra_scripts = []
Override the variable in conf.py:
html_theme_options = {
'extra_scripts': ['_static/test.js']
}
Say I have a template layout saved in template.html. This template includes a banner, side navigation, content container, and footer. Can I use flask to break up these page elements in such a way that I can have files such as banner.html, sidenavigation.html, etc. and render these different files within template.html?
From: http://jinja.pocoo.org/docs/templates/#include
template.html
{% include 'banner.html' %}
{% include 'sidenavigation.html' %}
{% include 'content.html' %}
{% include 'footer.html' %}
By default, Flask uses Jinja2 as its template engine. See Jinja's Template Designer Documentation how it's done.
Before you start, you need to write these components separately to other html files as pure html. For example, these files shouldn't contain any jinja syntax. After that, according to the documentation, you can easily import them into your template.html file by calling {% include 'filename.html' %} code.