peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.38k stars 203 forks source link

Directly render Blazor component on PHP page (ASP.NET Core 8) #1124

Open marinasundstrom opened 1 year ago

marinasundstrom commented 1 year ago

I want to embed a Razor component in a PHP page.

I would like to render a Razor component in any render mode directly on a PHP page - which should be possible with ASP.NET Core 8.

I have experience from rendering CSHTML partials in previous projects - for the Peachpie-based Wordpress specifically, but I want to do it the new way as of .NET 8.

marinasundstrom commented 1 year ago

Basing this on the existing methods in Peachpie: https://github.com/peachpiecompiler/peachpie/blob/cdcb9348ee847e579f9ad8e32c8a0434c5d822de/src/Peachpie.AspNetCore.Mvc/HttpContextExtension.cs#L23

Perhaps this will be of use when rendering: https://github.com/dotnet/aspnetcore/blob/426ed0fe108dec7cdb713815780d446d163a764c/src/Components/Endpoints/src/Results/RazorComponentResultExecutor.cs

Here is the more user-friendly API: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-components-outside-of-aspnetcore?view=aspnetcore-8.0

Then there is the issue with allowing interactivity by serving the necessary script, which I have solved: https://github.com/marinasundstrom/BlazorMinimalApiTest

Hopefully, they will open this up, and support this. The issue is: https://github.com/dotnet/aspnetcore/issues/50762

marinasundstrom commented 1 year ago

Here's an incomplete POC: https://github.com/marinasundstrom/BlazorPhp

It can only render components as static HTML. The renderer doesn't support the other render modes.

I wanted to use the EndpointHtmlRenderer but unfortunately, it is internal.

jakubmisek commented 1 week ago

Hello @marinasundstrom , is there anything we can improve/implement in our API?