A prebuilt, config-driven PageMeta struct — the recommended setup as of 0.2.0.
Instead of hand-rolling a defstruct and wiring it with use PhoenixPageMeta, use this struct directly:
def page_meta(socket, :show) do
%PhoenixPageMeta.PageMeta{title: "Hello", path: "/hello"}
endThe field set is built at compile time from a fixed base plus an optional, config-driven extension. Site-wide values come from config rather than being repeated as per-page struct defaults.
Struct fields
Always present:
:title,:path— required (@enforce_keys):breadcrumb_title,:parent,:skip_breadcrumb— breadcrumb trail:description,:canonical_path,:og_image,:og_image_alt,:json_ld,:locale— SEO meta tags:noindex(defaultfalse):og_type,:site_name,:twitter_site,:supported_locales— defaults sourced from config (see below)
Config
config :phoenix_page_meta,
# site-wide defaults baked into the struct (per-page overridable):
og_type: "website",
site_name: "Example",
twitter_site: "@example",
supported_locales: [:en, :es],
# extra struct fields (bare atoms and {key, default} pairs may be mixed):
extra_fields: [icon: nil, modal: false],
# optionally make extra fields required (appended to :title/:path):
extra_enforce_keys: [],
# base URL resolution (see below):
base_url: "https://example.com",
lang_path: &MyApp.I18n.lang_path/2The base URL is auto-detected from the single running Phoenix.Endpoint, so
in the common case no :base_url/:endpoint config is needed. Override only
when detection is ambiguous or you want a fixed URL.
Compile-time config
Field-set and default config (:extra_fields, :extra_enforce_keys, :og_type,
:site_name, :twitter_site, :supported_locales) is read with
Application.compile_env/3. Changing it requires recompiling this package:
mix deps.compile phoenix_page_meta --force.
Summary
Types
A page metadata struct. The exact field set is determined at compile time
(base fields plus :extra_fields from config), so this is intentionally
loose.
Functions
Returns the list of fields the struct was compiled with.
Returns true if the link path matches this page or one of its ancestors.
See PhoenixPageMeta.active?/3.
Builds a breadcrumb trail. See PhoenixPageMeta.Breadcrumb.build/1.
Types
@type t() :: %PhoenixPageMeta.PageMeta{ breadcrumb_title: term(), canonical_path: term(), description: term(), json_ld: term(), locale: term(), noindex: term(), og_image: term(), og_image_alt: term(), og_type: term(), parent: term(), path: term(), site_name: term(), skip_breadcrumb: term(), supported_locales: term(), title: term(), twitter_site: term() }
A page metadata struct. The exact field set is determined at compile time
(base fields plus :extra_fields from config), so this is intentionally
loose.
Functions
Returns the list of fields the struct was compiled with.
Returns true if the link path matches this page or one of its ancestors.
See PhoenixPageMeta.active?/3.
Builds a breadcrumb trail. See PhoenixPageMeta.Breadcrumb.build/1.