Skip to content

Page Classes & Props

Inertia integrates directly with ProcessWire Custom Page Classes and implements the full Inertia.js v3 prop specification.

Attach Totoglu\Inertia\InteractWithInertia to site/classes/DefaultPage.php so every template Page Class inherits a consistent contract:

Method Purpose
inertiaWithData(): array Return page-specific props merged into every $page->inertiaRender() response.
inertiaViewData(array $pageObject = []): array Return server-only PHP variables (locale, head, or custom keys) passed to _inertia.php on initial full-page loads.
inertiaShared(): array Return per-page shared props attached only when that Page Class renders.
inertiaRender(string $component, array $props = []): PageResponse Bind $this as the active page and render the target frontend component.
`with(string array $key, mixed $value = null): self`

Register site-wide state in site/templates/_init.php or site/ready.php. Use shareOnce() for datasets that rarely change across visits (navigation trees, footer links, filter presets) and share() for per-request data (authenticated user, edit permissions):

<?php
declare(strict_types=1);
namespace ProcessWire;
/** @var ProcessWire $wire */
$inertia = inertia();
$pages = $wire->pages;
$user = $wire->user;
$page = $wire->page;
$inertia->shareOnce('navigation', function () use ($pages): array {
$items = [];
foreach ($pages->get('/')->children('limit=50') as $item) {
$items[] = [
'title' => (string) $item->title,
'url' => (string) $item->url,
];
}
return $items;
})->as('site_navigation')->until(3600);
$inertia->share([
'auth.user' => fn(): ?User => $user->isLoggedin() ? $user : null,
'canEdit' => fn(): bool => $page instanceof Page && $page->id > 0 && $page->editable(),
]);

Inertia provides six prop wrappers to control when data is evaluated, cached, merged, or included during partial reloads.

Wrapper Method When Evaluated Best For
DeferredProp $inertia->defer($cb, $group) Asynchronously after initial page render Expensive secondary queries, recommendations, sidebar stats
ScrollProp $inertia->scroll($cb)->matchOn('id') Initial load + infinite scroll pagination Paginated ProcessWire PageArray feeds
MergeProp $inertia->merge($value) Initial load + partial reloads (appends/prepends/deep-merges) Activity feeds, chat messages, incremental lists
OnceProp $inertia->once($cb)->as($key)->until($ttl) Once per client session or cache TTL Navigation trees, dropdown options, reference catalogs
OptionalProp $inertia->optional($cb) Only when explicitly requested via partial reload only On-demand modals, audit logs, heavy inspector tabs
AlwaysProp $inertia->always($value) Every visit, even when excluded by partial reload filters Permissions, active CSRF/session state, security banners
<?php
declare(strict_types=1);
namespace ProcessWire;
/** @var Page $page */
/** @var Pages $pages */
$inertia = inertia();
return $inertia->render('Articles/Index', [
'page' => $page,
// 1. Evaluated in a background request after initial render (and cached for 30 minutes)
'stats' => $inertia->defer(fn(): array => [
'total' => $pages->count('template=article'),
], 'sidebar')->once(until: 1800),
// 2. Infinite scroll pagination backed by ProcessWire PaginatedArray
'articles' => $inertia->scroll(
fn(): PageArray => $pages->find('template=article, limit=12, sort=-created')
)->matchOn('id'),
// 3. Merge incremental slices across partial reloads (supports append, prepend, deepMerge)
'activity' => $inertia->merge($activitySlice)->append('items', matchOn: 'id'),
// 4. Cached across navigations in WireCache and browser memory
'categories' => $inertia->once(
fn(): PageArray => $pages->find('template=category, sort=title, limit=50')
)->as('article_categories')->until(3600),
// 5. Evaluated only when explicitly requested via router.reload({ only: ['auditLog'] })
'auditLog' => $inertia->optional(fn(): array => []),
// 6. Included on every response even during partial reloads
'permissions' => $inertia->always([
'editable' => $page->editable(),
]),
]);

When you omit ->until() on an OnceProp, Inertia automatically inherits $page->template->cache_time and invalidates its WireCache entry on Pages::saved, Pages::trashed, and Pages::deleted according to ProcessWire’s $template->cacheExpire policy.

Next steps