Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wpdotnet as component in Blazor project #100

Open
hojjatnikan opened this issue Mar 29, 2021 · 13 comments
Open

Use wpdotnet as component in Blazor project #100

hojjatnikan opened this issue Mar 29, 2021 · 13 comments

Comments

@hojjatnikan
Copy link

How can I use this 'wpdotnet' project as a component in the blazor project and have a page called blog that displays the 'wpdotnet' project?
For example www.example.com/blog
Someone can guide me

@marinasundstrom
Copy link

A Wordpress site is literally its own app, and they are usually hosted separately.

The solution, if you want to map the URL, is to configure the server to map /blog to the Wordpress app that is running separately. For that you would usually use a reverse proxy.

So there is no way to actually integrate it into and existing Blazor project/app. And why would you?

@jakubmisek
Copy link
Collaborator

Actually, WpDotNet is a part of your Asp.Net Core application request pipeline. So you can combine it with your other razor views and request delegates.

At this point - https://docs.peachpie.io/scenarios/wordpress/overview/#quick-start - in Startup class, you are free to prepend app.UseWordPress(); with other request delegates.

In the case of Blazor - feel free to experiment, but it can't run on the client-side for sure (it needs to communicate with MySql and to access the server's file system).

@marinasundstrom
Copy link

@hojjatnikan Just to elaborate my answer:

It did not occur to me that you could map different endpoints in the same app, as it is not a case that I have found desirable.

So @jakubmisek is right there.

I would personally keep the apps separate since mixing them makes it harder to maintain. And… If your main site is down then the blog is down too.

Anyway, you could use YARP (Reverse Proxy for .NET) in your main site to proxy /blog to the Wordpress site.

Unless you want tight integration between main site and blog then I would recommend this approach.

In my projects I’m hosting Blazor components in Wordpress pages via Razor views.

@XeonG
Copy link

XeonG commented May 1, 2021

Would be great to see more write tuts on doing this stuff.. would like to move away from using wordpress php and using c# for this stuff as finding a good cms for c# is well.. not really found anything decent yet

@marinasundstrom
Copy link

Would be great to see more write tuts on doing this stuff.. would like to move away from using wordpress php and using c# for this stuff as finding a good cms for c# is well.. not really found anything decent yet

I enjoy the backend parts of Wordpress, but I would like the ability to write my frontend/theme entirely in Razor syntax, perhaps even a Blazor app.

I wonder how hard it would be to plug into that part of Wordpress.

@jakubmisek
Copy link
Collaborator

jakubmisek commented May 2, 2021

@RobertSundstrom creating a theme in razor shouldn't be that difficult; I'd create a dummy theme in PHP which would include your razor component. (there is a short demo at https://www.peachpie.io/2018/08/razor-partial-view-on-php-page.html and https://github.com/iolevel/peachpie-samples/tree/master/mvc)

@marinasundstrom
Copy link

@jakubmisek Sure, I have been doing that for individual pages. What I'm not sure about is how to build a theme that is fully Blazor. Where you, at least, can access the most common functions to render content.

@jakubmisek
Copy link
Collaborator

@RobertSundstrom hmm combining it with blazor and application state might be a challenge. I'm not sure what's needed to achieve that.

@marinasundstrom
Copy link

I don't know how Wordpress works, when it loads the data of a page. Is it just routing to page based on a convention? Couldn't you just map that route to a ASP.NET Route? And then just inject the WP_Post into a Razor Page or a Blazor component? And write some interop code where it is needed.

@jakubmisek
Copy link
Collaborator

yes, it routes the page request and ends up by including various template-part PHP files (i.e. calling the main method of the file). We can put a breakpoint into a template file to see what's on the call stack.

@marinasundstrom
Copy link

@hojjatnikan @jakubmisek

You can build a frontend using the technology of your choice, be it Blazor or React, with Wordpress just for content management - using Wordpress as a "Headless CMS". The Wordpress API: https://developer.wordpress.org/rest-api/

@marinasundstrom
Copy link

Here is my headless Wordpress with a Blazor frontend: https://github.com/robertsundstrom/headless-wordpress-blazor

@tharlab
Copy link

tharlab commented Dec 5, 2021

maybe there is integration with blazor-oqtane multisite multi tenant architecture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants