Unified API for rendering design-system components across Nunjucks (Node), Twig (PHP), and Razor (.NET).

Contract

{ "type": "<component-id>", "params": { } }

The Nunjucks global returns a SafeString (same as calling a component macro), so you do not need | safe in templates when autoescape is on.

Node module (src/js/asp-component/)

File Role
index.js Public exports
contract.js Contract shape, validation, shared id/macro regexes
component-manifest.js Loads src/component-manifest.json
create-asp-component.js createAspComponent() / renderAspComponent()
register-nunjucks.js Registers global aspComponent + indent filter
ensure-indent-filter.js Nunjucks indent shim for action templates

Manifest

Manifest entries may include dotnet: { view: "Footer" } when a Razor view exists under src/dotnet/components/<id>/.

validate:contracts also checks that every component with a JSON Schema has a manifest entry.

.NET / Razor

Implementation under src/dotnet/ (NuGet package AspFrontend):

Piece Role
AspComponent/IAspComponentRenderer Public aspComponent API
AspComponent/AspComponentHtmlExtensions @await Html.AspComponentAsync(...) in Razor
AspComponent/Mapping/*ParamsMapper.cs params → view model
components/<id>/*.cshtml Markup (same output as tag helpers)
components/<id>/*TagHelper.cs Optional hand-authored Razor API

Razor (aspComponent):

@await Html.AspComponentAsync("notification", new {
    title = "Notice",
    modifier = "green",
    content = new { text = "…" }
})

Register in Program.cs with .AddAspFrontend(). In _ViewImports.cshtml:

@addTagHelper *, AspFrontend
@using PoliceDigitalServices.AspFrontend.AspComponent

Only action, footer, and notification are currently supported via aspComponent in .NET. Other components may have Nunjucks/Twig macros only until a Razor view and params mapper are added.

The NuGet package ships Razor views and tag helpers only. Load CSS and JavaScript from the npm/CDN package in consuming apps.

PHP

src/php/timber-twig-asp-component.php — Twig function aspComponent, reads the same manifest JSON.

Related

Source

Imported from docs/asp-component.md in asp-frontend.