Rendering Pipeline — PageBuilder

Capture the body first, then render the final document from the completed page model.

1

Capture Body

The layout renders RenderBody() into a temporary StringWriter instead of sending it directly to the response. Components rendered during body capture can register scripts, stylesheets and metadata.

var originalWriter = ViewContext.Writer;
var bodyWriter = new StringWriter();

try
{
    ViewContext.Writer = bodyWriter;
    RenderBody().WriteTo(ViewContext.Writer, HtmlEncoder);
}
finally
{
    ViewContext.Writer = originalWriter;
}
2

Enrich Page Model

Builders rendered during body capture register scripts, links, inline styles or metadata into PageInformation . This is the key advantage of the body-first pipeline — assets are component-driven.

// Inside any component or effect builder
PageInformation page = PageRegistry.GetOrCreatePageInformation(httpContext);
page.SetStylesheet("/css/imageEffect/BlurToSharpEffect.css");
page.SetScriptFile("/js/myComponent.js");
3

Render Document Start

Once the body is fully captured, the layout retrieves the completed PageInformation and emits the doctype, opening tags and the complete head — including all registered assets.

var bodyHtml = bodyWriter.ToString();
PageInformation page = PageRegistry.GetPageInformation(Context) ?? new PageInformation();
PageBuilder builder = Html.PageBuilder(page);

@builder.RenderDocumentStart(Context)

Inject Body & Finish

The captured body HTML is injected into the final document body. RenderDocumentEnd emits end-of-body assets (scripts) and closing document tags, completing the full page.

@Html.Raw(bodyHtml)
@builder.RenderDocumentEnd(Context)
Body-First Advantage

Components register their own CSS and JS during body rendering — the document head always contains exactly what the page needs, nothing more.

Explore Further

Go back to the introduction for a complete overview of PageBuilder capabilities.

Introduction