Cherry.Theme.RenderContext (cherry v0.2.0)

Copy Markdown View Source

Everything the layout wrap needs beyond the inner template's own assigns: the site, the active theme, the page title, the framework-owned SEO head block, and the navigation.

One value instead of a growing argument list — pages differ only in title and head, so for/3 derives a page's context from the base.

Summary

Functions

Derives a page's context from the base: same site/theme/nav.

Types

t()

@type t() :: %Cherry.Theme.RenderContext{
  head_extra: String.t(),
  nav: [Cherry.Theme.NavItem.t()],
  page_class: String.t(),
  page_title: String.t(),
  search: String.t() | nil,
  site: Cherry.Site.t(),
  theme: Cherry.Theme.t()
}

Functions

page(context, page_title, head_extra, page_class \\ "")

@spec page(t(), String.t(), String.t(), String.t()) :: t()

Derives a page's context from the base: same site/theme/nav.

page_class is the layout's body class (page-home, page-guides, page-post, …) so a theme can restyle whole sections without new templates.

search carries the configured engine ("cherry", "pagefind", or nil) rather than a boolean, because the two engines need different markup and assets; <%= if @search do %> still reads as "search is on" in a template.