Server-to-client page context system.
Renders a JSON blob into a hidden input (#pa-page-context) that JS can read
synchronously on page load — no API fetch needed. CSP-safe (no inline scripts
with data).
How it works
- The app registers context providers via config
- The library's
page_context/1component renders the hidden input - JS reads it via
getPageContext()/getContextValue(key)
Configuration
# config/config.exs
config :keen_pure_admin,
page_context_providers: [
&MyApp.PageContext.theme_manifests/1,
&MyApp.PageContext.user_context/1
]Each provider is a function that receives the assigns map and returns a map to merge into the context.
Provider Examples
defmodule MyApp.PageContext do
def theme_manifests(_assigns) do
%{"themeManifests" => load_manifests()}
end
def user_context(assigns) do
user = assigns[:current_user]
%{"user" => %{"id" => user.id, "locale" => user.locale}}
end
endStandard Keys
| Key | Type | Description |
|---|---|---|
themeManifests | object | Theme manifests (avoids /api/themes/manifests fetch) |
version | string | Context schema version |
timestamp | integer | Server render time (unix seconds) |
user | object | Current user (app-provided) |
translations | object | UI translations (app-provided) |
locale | string | Current locale (app-provided) |
Summary
Functions
Builds the page context map by calling all configured providers.
Functions
Builds the page context map by calling all configured providers.
Providers are functions (assigns :: map()) -> map() registered via:
config :keen_pure_admin,
page_context_providers: [&MyModule.provider/1]The base context includes version and timestamp. Provider results
are merged on top (last provider wins on key conflicts).