Skip to content

A header!

information = 'You can even put MkNodes here!'

Templates

The page template can be edited easily via the [MkPage.template][mknodes.PageTemplate] attribute. If any block gets modified then MkNodes will generate an individual template HTML file for the page during the build process.

An example:

page.template.tabs.content = mk.MkAdmonition("Some text.")
would generate the following template override automatically:

{ % extends "main.html" % }

{ % block content % }
<div class="admonition info">
<p class="admonition-title">Info</p>
<p>Some text</p>
</div>

{ % endblock % }
page.template.announce.content = mk.MkMetadataBadges(typ="classifiers")
page.template.footer.content = mk.MkProgressBar(50)
page.template.tabs.content = mk.MkCode("information = 'You can even put MkNodes here!'")
page.template.hero.content = mk.MkHeader("A header!")

PageTemplate Blocks

Title block ([MkPage.template.title][mknodes.pages.templateblocks.TitleBlock])

The title block allows to modify the title tag in HEAD

page.template.title.content = "New title"

Libs block ([MkPage.template.libs][mknodes.pages.templateblocks.LibsBlock])

The libs block can be used to add additional JavaScript libraries.

page.template.libs.add_script_file("path_to_file.js")

Analytics block ([MkPage.template.analytics][mknodes.pages.templateblocks.AnalyticsBlock])

The analytics block can be used to set custom analytics.

page.template.analytics.content = "<html content>"

Scripts block ([MkPage.template.scripts][mknodes.pages.templateblocks.ScriptsBlock])

The scripts block can be used to add custom JavaScripts, put at end of HTML body.

page.template.scripts.add_script("JavaScript code")

Site meta block ([MkPage.template.site_meta][mknodes.pages.templateblocks.SiteMetaBlock])

The site_meta block contains the site metadata. By default it gets populated by data from the MkDocs config file.

Styles block ([MkPage.template.styles][mknodes.pages.templateblocks.StylesBlock])

The styles block can be used to add additional CSS.

page.template.styles.add_css("My custom CSS")

ExtraHead block ([MkPage.template.styles][mknodes.pages.templateblocks.ExtraHeadBlock])

The extrahead block allows to add content to the HTML head which does not suit the other categories, like redirecting to another URL.

page.template.extra_head.set_redirect_url("http://some.url")

HTML blocks

HTML blocks can get populated with Markdown, which will get converted to HTML during the build process.

  • [MkPage.template.content_block][mknodes.pages.templateblocks.HtmlBlock]
  • [MkPage.template.footer][mknodes.pages.templateblocks.HtmlBlock]
  • [MkPage.template.site_nav][mknodes.pages.templateblocks.HtmlBlock]

MkDocs-Material-exclusive blocks:

  • [MkPage.template.tabs][mknodes.pages.templateblocks.HtmlBlock]
  • [MkPage.template.outdated][mknodes.pages.templateblocks.HtmlBlock]
  • [MkPage.template.hero][mknodes.pages.templateblocks.HtmlBlock]
  • [MkPage.template.announce][mknodes.pages.templateblocks.HtmlBlock]
page.template.announce.content = mk.MkMetadataBadges(typ="classifiers")
page.template.footer.content = mk.MkProgressBar(50)
page.template.tabs.content = mk.MkCode("information = 'You can even put MkNodes here!'")
page.template.hero.content = mk.MkHeader("A header!")
Page info
Code for this page
mknodes.manual.page_section._
@nav.route.page("Templates", hide="toc", status="new")
def _(page: mk.MkPage):
    page += mk.MkTemplate("pages/page_templates.jinja")
    page.template.announce.content = mk.MkMetadataBadges(typ="classifiers")
    page.template.footer.content = mk.MkProgressBar(50)
    code = "information = 'You can even put MkNodes here!'"
    page.template.tabs.content = mk.MkCode(f"{code}")
    page.template.hero.content = mk.MkHeader("A header!")
    css = {
        ":root": {
            "--md-primary-fg-color": "#FF0000",
            "--md-primary-fg-color--light": "#FF0000",
            "--md-primary-fg-color--dark": "#FF0000",
        },
    }
    page.template.styles.add_css(css)
Resources
Resources(css=[],
          markdown_extensions={'attr_list': {},
                               'md_in_html': {},
                               'pymdownx.emoji': {'emoji_generator': <function to_svg at 0x7fd7a6931800>,
                                                  'emoji_index': <function twemoji at 0x7fd7a69316c0>},
                               'pymdownx.magiclink': {'repo': 'mknodes',
                                                      'repo_url_shorthand': True,
                                                      'user': 'phil65'}},
          plugins=[],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/mknodes/manual/page_section.py
  source_function: null
  source_line_no: 54
hide:
- toc
status: new
template: MkPages/templates.html
title: Templates

50%