Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Utility filters

The jinja2 environment also contains some pre-defined filters.

Note

The output gets passed to the first argument of the filter function. Filters are separated from the variable by a pipe symbol (|) and may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.

A base collection of filters is provided by jinjarope

Additional filters provided by MkNodes:

Example:

"PageName" | get_link

def get_link(target: LinkableType, title: str | None = None, from_page: mk.MkPage | None = None)

Return a markdown link for given target.

Target can be a class, a module, a MkPage, MkNav or a string.

Parameters:

NameTypeDescriptionDefault
targetLinkableTypeThe thing to link to
titlestr | NoneThe title to use for the linkNone
from_pagemk.MkPage | NonePage the link is for (to create relative links to own pages)None

get_url

Example:

"PageName" | get_url

def get_url(target: LinkableType) -> str

Get a url for given target.

Target can be a class, a module, a MkPage, MkNav or a string.

Parameters:

NameTypeDescriptionDefault
targetLinkableTypeThe thing to link to

TODO

Page info
Code for this page

mknodes.manual.templating_section._

@nav.route.page("Utility filters")
def _(page: mk.MkPage) -> None:
    page += mk.MkTemplate("templating/template_filters.jinja")

Resources
Resources(css=[],
          markdown_extensions={},
          plugins=[],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/templating_section.py
  source_function: _
  source_line_no: 50
title: Utility filters