Skip to content

Extending Asset & Result Rendering with Render Hooks

Render hooks are not the normal CSS or JavaScript loading mechanism. Use the typed Frontend resource graph for ordering, deduplication, lazy activation, CSP diagnostics, and output safety.

The Render Hook system lets you inject custom content into asset and result components at specific locations—without overwriting Blade files. This is the recommended, future-proof way for any package to extend Capell Frontend UI.


  • Register extensions for named locations using the RenderHookLocation enum (e.g. BeforeTitle, AfterTitle, Footer, BeforeResult, AfterResult, AssetTags, etc).
  • Each extension receives a RenderHookContext DTO (with location, item, and extensible data) and returns HTML/Blade output.
  • Extensions can be:
    • Closures
    • Classes implementing RenderHookExtensionInterface
    • Blade view/component names (as strings)
  • All registered extensions for a location are rendered at the corresponding hook in the UI, sorted by priority (lower numbers first).
  • Granular control: You can scope a hook registration to a specific scenario (e.g. only for assets, or only for a specific Blade file/component) using the scenario and target parameters.

In your package’s service provider:

use Capell\Core\Data\Rendering\RenderHookContext;
use Capell\Frontend\Enums\RenderHookLocation;
use Capell\Frontend\Support\Render\RenderHookRegistry;
// Register for all assets
app(RenderHookRegistry::class)->register(
RenderHookLocation::AfterTitle,
function (RenderHookContext $context) {
return view('your-package::partials.asset-badge', ['context' => $context])->render();
},
10, // priority
'asset' // scenario
);
// Register for a specific file/component
app(RenderHookRegistry::class)->register(
RenderHookLocation::AfterTitle,
'your-package::components.asset-badge',
10, // priority
'asset', // scenario
'asset/tile.blade.php' // target
);

When rendering, the scenario and target are passed automatically by the Blade component:

{!!
app(RenderHookRegistry::class)->renderAll(
RenderHookLocation::AssetTags,
[
'tags' => $tags,
'item' => $item ?? null,
],
'asset',
'asset/tile.blade.php',
)
!!}

Layout Builder and theme layout/container views can read the current public render DTO with \Capell\Frontend\Support\Render\PublicRenderDataScope::current(). It returns ?PublicPageRenderData: null outside a Blade response render, including standalone component renders. Use its preparedWidgetHtml() accessor for prepared widget content. The main-content hook also receives this DTO in MainContentRenderHookData::$publicRenderData.

PublicPageRenderData holds hydrated Data only and implements the PublicRenderData marker, so the capell.publicRenderDataModel PHPStan rule rejects any Eloquent model added to it. Read the page, site, language, layout and theme from its context (PublicRenderContextData), never from models.

The response renderer enters this scope after PublicLayoutRenderPreparer runs and restores the previous value in finally, including nested renders and exceptions. Do not retain the DTO beyond that render or pass it as a component attribute: legacy anonymous theme overrides may merge or serialise $attributes.

Hooks are available in:

  • x-capell::asset.tile (BeforeContent, BeforeTitle, AfterTitle, Footer)
  • x-capell::asset.index (BeforeTitle, AfterTitle, Footer)
  • x-capell::page.results (BeforeResult, AfterResult)
  • x-capell::app (BodyEnd) and layout/header/footer components (MainContent, HeaderAfter, FooterBefore, FooterAfter)

  1. Create a Blade partial or component in your package:
{{-- resources/views/components/asset-badge.blade.php --}}
@if ($context->item['is_featured'] ?? false)
<span class="badge badge-featured">Featured</span>
@endif
  1. Register the extension for the desired location and scenario (see above).

  • Lower priority numbers render first.
  • Multiple packages can register for the same location—output is composable.

  • The RenderHookContext DTO provides the hook location and the current item.
  • Extend this DTO if you need to pass more data in the future.

  • Implement Capell\Core\Contracts\Rendering\RenderHookExtensionInterface for reusable, testable extensions. It receives Capell\Core\Data\Rendering\RenderHookContext, so a runtime package can implement the hook without depending on Frontend.
  • Register the hook from a frontend provider through FrontendHookRegistrar or RenderHookRegistry. Frontend owns placement, cache safety and rendering.
  • The previous Capell\Core\Contracts\Rendering\RenderHookExtensionInterface and Capell\Core\Data\Rendering\RenderHookContext names remain aliases for existing integrations.

  • See tests/Unit/RenderHookExtensionRegistryTest.php in this package for real-world examples, including scenario/target-specific hooks.

  • Extensions are rendered in the order of their priority for each location.
  • You have full access to the current context object.
  • This mechanism is additive and composable—multiple packages can contribute extensions at any hook.
  • Prefer this system over Blade overrides for maintainability and upgrade safety.
  • Use scenario/target scoping for granular control when needed.

Register replacements in a frontend service provider using HeadMetadataRegistry::register($key, $value). The last registration for a key replaces its default without affecting other keys, except robots directives are merged. String keys are og:title, og:description, og:type, og:url, og:site_name, og:image, twitter:card, twitter:title, twitter:description, twitter:image and robots. By default og:image and twitter:image use the page’s social image, then its featured image, then the site’s default image, and the card becomes summary_large_image when one exists; a package such as the SEO Suite replaces them by registering or emitting the same keys. The jsonld:WebSite and jsonld:WebPage keys accept associative arrays representing schema.org graph nodes. Values are escaped when rendered. Register metadata through this contract instead of emitting the same tags from an unkeyed head hook.

Legacy head hooks, site, theme and page snippets, custom head views and the meta section are folded into the same keys before defaults render. Later legacy values replace earlier ones and explicit registry values take precedence, except robots directives are merged across all sources. Restrictive directives cannot be overridden by permissive ones; error and installation pages retain noindex. Unrelated head markup is preserved. JSON-LD nodes of other types remain in their original contributions.

Managed metadata in body output and rehydrated fragments is suppressed in favour of the head values. Register managed keys through HeadMetadataRegistry; when managed metadata is stripped from a fragment, a warning identifies the hook.