Expand description
Viewer-aware access helpers for public templates (#members).
The built-in menus (auto_menu(), curated menu()/_menus) already
hide pages the current viewer can’t access. These Tera helpers extend
the same protection to hand-written links and lists:
{{ child | can_view }}/can_view(page=child)— a boolean: may the current viewer see this page? Guard a raw link with it:{% if child | can_view %}<a href="{{ child | page_href }}">…</a>{% endif %}.{{ children | visible }}— filter a list of page-shaped objects (or menu items) down to the ones the viewer may access. Recurses into a nestedchildrenkey, so nested menus / page trees are filtered at every level in one call.
Both read a render-scoped AccessContext the pipeline installs (via
install) right before tera.render — the same await-free
thread-local pattern as pageurl / auto_menu (Tera 1.x can’t pass
the context into fn/filter args). With no context installed, or on a
tenant with nothing gated, both helpers treat every page as visible —
the guard (crate::view_restriction_guard) is still the actual
access control; these helpers are only a rendering convenience.
Page-shaped values are matched on their path (materialized tree
path) + page_type_id — present on the children / ancestors
context vars and on any serialized crate::page::Page. A value
lacking path is treated as visible (the helper can’t decide; the
guard still protects the target).
Structs§
- Access
Guard - RAII guard. While in scope the access context is installed; on drop
it’s cleared. Bind it across
tera.render(…)and let it drop after.
Functions§
- install
- Install
ctxfor the duration of the returned guard socan_view/visibleresolve against it on this thread. - register_
tera_ function - Register
can_view(function + filter) andvisible(filter) ontera. Wired fromcrate::urls::register_tera_helpers.