Skip to main content

Module page_view

Module page_view 

Source
Expand description

What a page type serves on its public URL, and how Accept picks.

Most page types render a Tera template. Some — feeds a CRM consumes, endpoints that only ever answer machines — have no template at all and exist purely to return JSON. Before this module that was unsayable: crate::page_type::PageTypeHandler::default_template is a required &'static str, and render_inner hands whatever it finds straight to Tera, so a blank template is a 500.

Two enums, deliberately distinct:

  • PageViewMode is what the operator declares and what the cms_page_type.view_mode column stores. Auto is the default and means “work it out from the template”.
  • PageViewKind is what resolve_kind decides, and it is the only thing the renderer branches on.

§Auto never opens a JSON view on a page that has a template

It would be tempting to make Auto mean “negotiate on everything”. That would silently publish a JSON representation of every page’s extension + builder values on every existing site the moment this ships — including hosts that deliberately never mounted crate::api::router. So Auto + a template is HTML-only and ignores Accept entirely. Since every existing cms_page_type row has a non-empty default_template, the upgrade is a no-op. Serving JSON from a page that also renders HTML is opt-in via PageViewMode::Api.

Enums§

Accept
The coarse media-type preference distilled from an Accept header.
PageViewKind
What a page type can actually serve, once the declared mode and the template have been reconciled. This is what the renderer branches on.
PageViewMode
The declared mode, stored in cms_page_type.view_mode.

Functions§

kind_for
resolve_kind over a loaded registry row.
parse_accept
Parse an Accept header into a coarse preference.
resolve_kind
Reconcile a declared mode with the template actually on the row.