@using Microsoft.AspNetCore.Blazor.RenderTree

Fragment will be toggled below

@if (showFragment) { @ExampleFragment }

The end

@functions { bool showFragment; static RenderFragment ExampleFragment = builder => { // TODO: Improve syntax // Ideally we'd support inline Razor syntax here and are investigating this // Could be: // static RenderFragment ExampleFragment() // => @

Some text

Child text

; // spaced over multiple lines, of course // Failing that, we could have an C#-based representation, e.g., // new Element.P { "Some text", new Element.Div { "Child text" } }, etc. builder.OpenElement(100, "p"); builder.AddAttribute(101, "name", "fragment-element"); builder.AddAttribute(102, "style", "color: red"); builder.AddContent(103, "This is from the fragment"); builder.CloseElement(); }; }