greenoldman
greenoldman

Reputation: 21062

How to put base content in derived component?

I have base component with basic html content and derived component which adds decorations to it. But now I realized I don't know how to make blazor put base content within derived component. I am looking in my case for something like this:

<div>
<span>my derived decoration</span>
@base_content
</div>

How to tell Blazor to put "here" the base content?

Upvotes: 1

Views: 434

Answers (2)

Liam
Liam

Reputation: 5476

There's a Github post where a user is complaining the using the __builder field is "hacky" because its an internal field... the following was suggested which works as well and definitely looks better:

@((RenderFragment)base.BuildRenderTree)

Source: https://github.com/dotnet/aspnetcore/issues/47538

Upvotes: 2

pfx
pfx

Reputation: 23234

In your derived components .razor file include a call to base.BuildRenderTree(__builder) .

An example:

@inherits YourBaseComponent

<div>
<span>my derived decoration</span>

@{
    base.BuildRenderTree(__builder);
}

</div>

Upvotes: 3

Related Questions