Skip to content

Instantly share code, notes, and snippets.

@markadrake
Created March 11, 2024 17:02
Show Gist options
  • Save markadrake/7c9bea3d9479cfcf441e03378ffb9eac to your computer and use it in GitHub Desktop.
Save markadrake/7c9bea3d9479cfcf441e03378ffb9eac to your computer and use it in GitHub Desktop.
Umbraco — Blocks in Rich Text Editor

Blocks in the RTE use a special type, RichTextBlockItem, that can't automatically be converted to BlockListItem. During render, Umbraco is hardcoded (!) to look in a specific location, and will not fallback (!) to other locations. Instead of copy and pasting code, we use a simple trick to pass rendering off to the real template.

References:

@*
Block alias: `Example`
File path: Views/Partials/RichText/Components/Example.cshtml
*@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.RichTextBlockItem>
@{
var blockListItem = new BlockListItem(Model.ContentUdi, Model.Content, Model.SettingsUdi, Model.Settings);
}
<partial name="~/views/partials/blocklist/components/example.cshtml" model="blockListItem" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment