ContentRenderer
ContentRenderer renders the body of a content item and nothing else: no title, metadata or links. Use it when you
lay out the header, sidebar and footer of an article yourself and only need the Markdown output in the middle.
Package Osirion.Blazor.Cms.Web, namespace Osirion.Blazor.Cms.Web.Components. Source on GitHub.
Version 1.5.0 was released on 21 April 2025. This post is kept for history; the current release is 4.0.0, described in Osirion.Blazor 4.0: security hardening and Fluent UI v5.
Added
- A fluent API for service registration through the
AddOsirionBlazormethod, with theIOsirionBlazorBuilderinterface. - CSS framework integration for Bootstrap, Fluent UI, MudBlazor and Radzen: the
CssFrameworkenum, classes that map Osirion's CSS variables to each framework's variables, and aFrameworkIntegrationparameter onOsirionStyles. OsirionStyleOptions, a class of its own for styling options.
Changed
osirion-cms.csswas renamed toosirion.css, because it styles every component, not only the CMS ones.- Styling options moved from
GitHubCmsOptionstoOsirionStyleOptions. - The service collection extensions were reorganized. The earlier methods kept working.
Upgrading to 1.5
Update the stylesheet link to osirion.css and move styling settings from GitHubCmsOptions to
OsirionStyleOptions. The 1.5 section of the migration guide
has the details.
These names belong to 1.5. Later versions changed the registration API (AddOsirion) and the theming options, so
follow the current documentation for new projects.
@using Osirion.Blazor.Cms.Domain.Entities
@using Osirion.Blazor.Cms.Domain.Services
@using Osirion.Blazor.Cms.Web.Components
@inject IContentProviderManager ContentProviders
@* The item is a page of this site's own content. ContentRenderer writes only its body, so the page supplies the
title. OmitLeadingTitle leaves out the body's own "# Title" line, which keeps this documentation page at one h1. *@
@if (item is not null)
{
<div style="max-height: 24rem; overflow: auto; padding: 1rem; border: 1px solid var(--osirion-border-color, #d1d5db); border-radius: 0.5rem;"
tabindex="0" role="region" aria-label="Body of the release notes page">
<ContentRenderer Item="@item" OmitLeadingTitle="true" />
</div>
}
else
{
<p>The sample page was not found in the content provider.</p>
}
@code {
private ContentItem? item;
protected override async Task OnInitializedAsync()
{
var provider = ContentProviders.GetDefaultProvider();
item = provider is null ? null : await provider.GetItemByUrlAsync("blog/osirion-blazor-v1-5-release-notes");
}
}The demo loads this site's own page for the 1.5 release notes and renders its body in a scrolling frame, with
OmitLeadingTitle so the body's own title line is left out.
Usage
@using Osirion.Blazor.Cms.Web.Components
<ContentRenderer Item="@item" />
A custom article layout around it. The page shows the title itself, so OmitLeadingTitle leaves out the heading line
the Markdown body starts with, and the page keeps a single h1:
@if (item is not null)
{
<article class="post">
<h1>@item.Title</h1>
<p class="post-meta">@item.Author, @item.DateCreated.ToString("MMMM d, yyyy")</p>
<ContentRenderer Item="@item" Class="post-body" OmitLeadingTitle />
</article>
}
ContentRenderer does not load anything; get the item from IContentProviderManager or a page component first.
ContentView leaves out the leading title itself, and so does ArticlePage while its hero or header shows the title.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
Item |
ContentItem? |
null |
The item whose Content (HTML) is rendered, sanitized, with code highlighting. Only the empty wrapper renders when the item or its content is null. The component loads nothing, so get the item from the content provider first. |
OmitLeadingTitle |
bool |
false |
Whether to leave out the content's opening top-level heading (a Markdown # Title line). Set it when the page already shows the item's title as its heading, so the title appears once and the page has a single h1. |
Theme |
ThemeMode |
ThemeMode.System |
The component's color mode. Light or Dark writes it to data-theme (data-bs-theme under Bootstrap) on the root element; System writes nothing. |
Class |
string? |
null |
Extra CSS classes for the component's root element. |
Style |
string? |
null |
An inline style for the component's root element. |
The Theme and Style rows come from the base class. ContentRenderer does not write them, or unmatched attributes, so only Class reaches the root element.
Behavior
- Rendering. The HTML is passed to OsirionHtmlRenderer with its default settings and rendered on the server under static SSR.
- Security.
OsirionHtmlRenderersanitizes the HTML with the registeredIHtmlContentSanitizerbefore writing it, so script, event handler attributes,javascript:anddata:URLs, forms, iframes and inline SVG never reach the page, whatever provider the item came from. - Code blocks. When the HTML contains code blocks, the renderer adds Prism 1.29.0 from cdnjs (verified with
Subresource Integrity) to highlight them. The code is readable without script; highlighting is an enhancement.
Line numbers and the copy button are off. To change these settings, or to self-host Prism with
PrismBaseUrl, useOsirionHtmlRendererdirectly withHtmlContent="@item.Content". - Live demos. The renderer's
EnableDemosdefault is on, so a fenceddemoblock in the body whose text is a registered demo key renders the live demo, as on this site. See OsirionContentDemo. - SEO. Nothing is written to the head.
Styling
The root element is a div with the class osirion-content-view (the same class as ContentView), containing
osirion-content-body and the renderer's article. The body takes its line height and text color from the theme
tokens --osirion-line-height-relaxed and --osirion-text-primary. The renderer links its own stylesheet,
_content/Osirion.Blazor.Core/css/osirion-html-renderer.min.css, which is not scoped to a component and styles the
body's headings, paragraphs, lists, blockquotes, tables, code and images; that is where the body's typography comes
from. This component's own stylesheet sets only the body's line height, color and bottom margin: rules for the body's
elements that it used to carry never matched, because the body's elements do not have the component's scope
attribute.
Related
- CMS pages: the group overview
- ContentView: the body plus header, metadata and footer
- HTML renderer: highlighting options and Prism settings