Skip to content

Utility filters

The jinja2 environment also contains some pre-defined filters.

Info

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

Return a markdown link for given target.

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

Parameters:

Name Type Description Default
target LinkableType

The thing to link to

required
title str | None

The title to use for the link

None

get_url

Example:

"PageName" | get_url

Get a url for given target.

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

Parameters:

Name Type Description Default
target LinkableType

The thing to link to

required

load_file

Example:

"Path/to.file" | load_file

dump_yaml

Example:

{"a": "b"} | dump_yaml

Dump a data structure to a yaml string.

Parameters:

Name Type Description Default
yaml_obj Any

The object to serialize

required

load_yaml

Example:

"site_name: MkNodes" | load_yaml

Load a yaml string.

Parameters:

Name Type Description Default
text str

the string to load

required
mode LoaderStr

the yaml loader mode.

'unsafe'
Page info
Code for this page
mknodes.manual.templating_section._
@nav.route.page("Utility filters")
def _(page: mk.MkPage):
    page += mk.MkTemplate("templating/template_filters.jinja")
Resources
Resources(css=[],
          markdown_extensions={'attr_list': {},
                               'md_in_html': {},
                               'pymdownx.emoji': {'emoji_generator': <function to_svg at 0x7fd32a7ad800>,
                                                  'emoji_index': <function twemoji at 0x7fd32a7ad6c0>},
                               '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: null
  source_line_no: 51
template: SUMMARY.html
title: Utility filters