layout template - customize HTML layout
Basic usage of layout template
You can use the template that comes with the theme, such as error pages, you can use 404.html
directly, just add the key value of layout
in metadata
---
layout: 404.html
---
Customize layout template
First write the layout template file, which supports the Jinja2
grammar, and the writing method can refer to the default [writing of the layout template of the theme plugin](https://github.com/teedoc/teedoc/tree/main/plugins/teedoc-plugin-theme- default/teedoc_plugin_theme_default/templates).
The template file can be placed in two places, one is placed in the theme plug-in, the plug-in author can do this;
The other is to put it in the layout template folder (the default document root directory layout
), and then use a specific layout template for a specific page separately, and add the layout
key value at the article header metadata
:
layout
: The layout template used by the page. This key value is not required by default. The configuration in the theme plugin will be used. You need to customize the layout of this page. You can set this parameter. The path is relative to the layout_root_dir in
site_configPath,
layout_root_dir
defaults to layout
, so to use layout/special_layout.html
only need to fill in special_layout.html
You can modify the template based on the theme, or inherit the template of the theme, such as slightly changing the body
part of the 404.html
page, just create a new my_404.html
in the layout
directory. Note that the file name cannot be the same Built-in file name conflict, if conflict, it will prompt generate html fail: maximum recursion depth exceeded in comparison
:
{% extends "404.html" %}
{% block body_404 %}
Here is body
{{ body|safe }}
{% endblock%}
Then use this template in 404.md
---
layout: my_404.html
---
jinja2 template variables
Here is a list of all supported variables:
page head info
lang
: language, e.g.en
, orzh-CN
metadata
: metadata from doc metadata, dict typepage_id
: page id , a string, set in doc config and doc metadatapage_classes
: page classes, a list, set in doc config and doc metadatakeywords
: keywords, a list, set in doc metadatadescription
: description, a string, set in doc metadataheader_items
: tags in head(<head></head>
) tag, a string listtitle
: page title, can be null, string, set in doc metadatasite_name
: site name, string, set in site configjs_vars
: js variables set and used by plugins, a dict object
navbar
logo_url
: site logo image url, string, can be null, set in doc configlogo_alt
: site logo alt info, string, can be null, set in doc confighome_url
: home url, e.g. "/", "/site0/", stringnavbar_title
: navbar title, html string, can be null, set in doc confignavbar_main
: navbar left html, html stringnavbar_options
: navbar right html, html stringnavbar_plugins
: navbar plugins html, html string
sidebar info
pages no sidebar, only article of docs have
sidebar_title
: sidebar title, string, can be html string, set in doc sidebar configsidebar_items_html
: sidebar items html, html string
body info
article of docs body info
article_title
: doc's article title, string, set in doc metadatatags
: article tags, a string list, set in doc metadataauthor
: article author, string, can be null, set in doc metadatadate
: article create date, string, can be null, set in doc metadatashow_source
: show source button info, string, can be null, set in site config and doc metadatasource_url
: source file's url, valid only when show_source is not nullbody
: body html, html stringprevious
: previous article, can be nulltitle
: previous article title, stringurl
: previous article url, string
next
: next articletitle
: next article title, stringurl
: next article url, string
toc
: toc html string, can be null
pages body info
body
: body html, html string
page footer info
footer_top
: footer top html stringfooter_bottom
: footer bottom html stringfooter_js_items
: js items last load int html, string list