Skip to main content

Golem Documentation

Michael Bernstein

Navigation Helpers Plugin

The nav_helpers plugin computes structured navigation aids for Chameleon templates, including hierarchical breadcrumb trails and flattened, depth-indexed navigation trees.

Overview & Features

  • Breadcrumb Hierarchy Resolution: Automatically traverses the site navigation tree to compute an ordered trail of ancestors from the site root ("Home") down to the currently viewed page.
  • Flattened Navigation Trees: Transforms nested hierarchical trees into an ordered sequence with explicit depth attributes, facilitating mobile drawer menus, sitemaps, and custom nav loops.
  • Current Page Awareness: Tags each breadcrumb node with an is_current boolean flag, enabling accessible aria-current="page" markup.

Enabling the Plugin

Add "nav_helpers" to the plugins list in golem.toml:

golem.toml
TOML
[plugins]
plugins = [
    "nav_helpers",
]

Or in pyproject.toml:

pyproject.toml
TOML
[tool.golem.plugins]
plugins = [
    "nav_helpers",
]

Configuration Reference

Options can be specified in the [plugins.nav_helpers] table in golem.toml:

golem.toml
TOML
[plugins.nav_helpers]
home_title = "Documentation"
home_url = "/"
Configuration Options

Option

Type

Default

Description

home_title

str

"Home"

Display label for the root breadcrumb ancestor.

home_url

str \| None

root_path or "/"

Link destination URL for the root breadcrumb entry.

===

Template Context Variables

When active, nav_helpers enriches the template context with two variables:

[cols=1,1,3]

===

Variable

Type

Description

breadcrumbs

list[dict]

Ordered list of ancestor dictionaries from root to current page. Each dictionary contains:

  • title (str): Page display title.
  • url (str): Destination link URL.
  • is_current (bool): True for the final (active) page item, False for ancestors.

nav_tree_flat

list[dict]

Ordered depth-first traversal of all navigation entries. Each dictionary contains:

  • title (str): Page title.
  • url (str): HTML link URL.
  • path (str): Source document path.
  • depth (int): Zero-based integer indicating nesting level in hierarchy.

Chameleon Template Integration

Rendering Breadcrumbs

The following pattern matches Golem's default skeleton.pt breadcrumb implementation with full ARIA accessibility:

themes/mytheme/skeleton.pt
HTML
<tal:block tal:define="crumbs breadcrumbs | nothing">
    <nav tal:condition="python: crumbs and len(crumbs) > 1" aria-label="Breadcrumb" class="breadcrumbs">
        <ol>
            <li tal:repeat="crumb crumbs" tal:attributes="aria-current python:'page' if (crumb.get('is_current') if isinstance(crumb, dict) else getattr(crumb, 'is_current', False)) else None">
                <a tal:condition="python: not (crumb.get('is_current') if isinstance(crumb, dict) else getattr(crumb, 'is_current', False))" href="${crumb.url}">${crumb.title}</a>
                <span tal:condition="python: (crumb.get('is_current') if isinstance(crumb, dict) else getattr(crumb, 'is_current', False))">${crumb.title}</span>
            </li>
        </ol>
    </nav>
</tal:block>

Rendering Flat Navigation Trees

The flattened tree is ideal for rendering indented navigation links or mobile drawer menus without writing recursive TAL macros:

themes/mytheme/skeleton.pt
HTML
<ul class="flat-nav-list" tal:condition="nav_tree_flat | nothing">
    <li tal:repeat="item nav_tree_flat" class="nav-item depth-${item.depth}">
        <a href="${item.url}" tal:attributes="href item.url">${item.title}</a>
    </li>
</ul>

API Reference

class NavigationHelpersPlugin

PYTHON
class NavigationHelpersPlugin(GolemPlugin):

Provide breadcrumbs navigation, flattened nav tree, and context helpers.

home_title (str)

Display title for the root home breadcrumb. Defaults to "Home".

home_url (str | None)

Target URL for the root home breadcrumb. Defaults to context root_path or "/".

Examples

PYTHON
from golem.plugins.nav_helpers import NavigationHelpersPlugin

plugin = NavigationHelpersPlugin(home_title="Home")

Attributes

name

Default value: 'nav_helpers'

home_title

Default value: home_title

home_url

Default value: home_url

init

PYTHON
def __init__(self, home_title: str = 'Home', home_url: str | None = None, **extra: Any) -> None:

Initialize navigation helpers plugin with home breadcrumb configuration.

home_title (str, optional)

Label for the site root breadcrumb entry. Defaults to "Home".

home_url (str | None, optional)

Link URL for the root breadcrumb entry. Defaults to None.

**extra

Additional plugin configuration options.

from_config

PYTHON
@classmethod
def from_config(cls, config: Any = None) -> NavigationHelpersPlugin:

Instantiate NavigationHelpersPlugin from site configuration or dictionary.

config (Any, optional)

Site configuration object or dictionary. Defaults to None.

NavigationHelpersPlugin

Configured plugin instance.

on_template_context

PYTHON
@hookimpl
def on_template_context(self, context: PageContext, doc_path: Path) -> PageContext:

Intercept and enrich template context with breadcrumbs and flattened nav tree.

context (PageContext)

Chameleon template context dictionary.

doc_path (Path)

Path to the documentation source file being processed.

PageContext

Enriched template context containing breadcrumbs and nav_tree_flat.