Jump to content

Split requests for template / view and controller / data


pwFoo
 Share

Recommended Posts

I try to separate the requests for a template file (html) and the data / json and searching for a way to do it without enable url segments for each template (or enable by hook / api runtime).

I'll build a autoload module and the request routing should be done there to send a template / view / html file OR execute the "controller" (page / PW template file) without the need of a switch case / if else inside of the page template file...

Any idea how to do it? UrlSegments would work with for example first segment "template" or "view" to request the html file, but would be nice to do it without the use of segments (maybe needed for other things and default disabled). Any PW API way to do it by request content type, urlSegment / QueryString or anything else hook? 

Or a special "api" page which use urlSegments, load the page given by urlSegment and verify request type (html or json) by compare page path with (loaded page path)?

Link to comment
Share on other sites

5 hours ago, pwFoo said:

I try to separate the requests for a template file (html) and the data / json

I'm not sure I understand. Do you want to build some sort of React/Vue/SPA and use your existing HTML templates plus "raw data" from JSON? Why not using PW .php templates in the first place? What's the big picture / goal?

Perhaps you'll find some ideas/hints in this thread:

 

Link to comment
Share on other sites

4 hours ago, dragan said:

I'm not sure I understand. Do you want to build some sort of React/Vue/SPA and use your existing HTML templates plus "raw data" from JSON?

Yes, similar to that. PW template could bei used AS controller / return json, but requests for HTML / views should be redirected to another file (for example "./site/template/views/*").

But I don't know how to separate both. Easiest way should be urlSegments, but another way would be nice. Both requests could be ajax.

Link to comment
Share on other sites

I think I'll move the requests to a module with a own "/api" page working with urlSegments. Page template just perform a "normal" page load (PW template = controller, separated view). Module use urlSegments to route requests as needed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...