Skip to content

Jinja Namespace

When a website build is started, MkNodes will collect as much information as possible about the context by inspecting the distribution info, the local git repository, the remote GitHub repository as well as other project-related information. That information is used to build a context. A large amount of MkNodes fallback to context info if no other info is explicitely set, thus enabling the nodes to display project information without explicitely "hardcoding" the project.

These are the available namespaces available in the Jinja2 environment:

metadata
Package information
git
Local repository information
github
Information about the remote repository
theme
Information about the theme being used

Take a look at the sections in the site nav in order to discover all available information in the environment.

The collected information is also used to populate the MkNodes-specific Jinja2 namespace. In combination with the MkNodes jinja filters, this allows to efficiently write documentation about your project as well as building project-agnostic websites / website parts which can be re-used across different projects.

Rendering CSS files

Data about the used theme (colors etc.) is also part of the context / project information. That information is used then to dynamically create CSS stylesheets during the build process.

Example:

This call would pass the module of the current context to MkPipDepTree and let it create a dependency graph:

{ { metadata.module | MkPipDepTree(direction="LR") } }
Page info
Code for this section
mknodes.manual.templating_section._
@nav.route.nav("Jinja Namespace")
def _(nav: mk.MkNav):
    def add_context_doc(container, context):
        container += mk.MkDocStrings(
            context,
            show_root_toc_entry=False,
            show_if_no_docstring=True,
            heading_level=4,
            show_bases=False,
            show_source=False,
        )

    for ctx in CONTEXTS:
        subpage = nav.add_page(ctx.__name__)
        add_context_doc(subpage, ctx)
    page = nav.add_page(is_index=True, hide="toc")
    variables = dict(namespaces=NAMESPACES)
    template = "templating/template_namespace_index.jinja"
    page += mk.MkTemplate(template, variables=variables)
Resources
Resources(css=[],
          markdown_extensions={'attr_list': {},
                               'def_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/templating_section.py
  source_function: _
  source_line_no: 44
hide:
- toc
template: SUMMARY.html
title: Jinja Namespace