Jump to content

Is this even a viable way to go about this?


louisstephens
 Share

Recommended Posts

 

So I reread my first draft, and it made absolutely no sense (I deleted it to hopefully better explain myself).  I am trying to make a system (that to me is a bit complicated) utilizing jquery and processwire together. My whole goal is to put a url like https://domain.com/launch?first_name=jim&occupation=builder in a script tag on another site(just a localhost .php page) to then pull out the data for that person and append to divs etc. Basically, the initial script tag would point to "launch" which has a content-type of "application/javascript". Using jquery, I would pull out the persons name and occupation and then make a specific ajax get request to "domain.com/api" (in json format) for a look up of the person. Essentially then I could pull that particular person's information from the json data, and do with it how I please in the "launch" page.  In processwire, I have a page structure like:

People
-Jim Bob (template: person )
--Occupations (template: basic-page)
---Builder (template: occupation)
---Greeter (template: occupation)

It is really just a bunch of people with their occupations and a few fields to the occupation template. With the "api" (template: api) url, I was hoping to return all the data (of people) in json format like:

Example Format:

{
    "id": 1,
    "title": "Jim Bob",
    "occupations": {
        "builder": {
            "id": 44,
            "title": "Builder",
            "years_worked": 1,
            "etc": "ect",
        },
        "Greeter": {
            "id": 44,
            "title": "Greeter",
            "years_worked": 1,
            "etc": "ect",
        },    }
}

Where I get lost is really outputting the page names and nesting in the occupations into json. I have used Pages2JSON before, but I was a bit lost on how to implement what i was thinking.

 

I have access to all the local host files, but I was hoping to kind of build out a "system" where I could place the script tag/parameters in any project, and be able to interact with the data without doing an ajax call on the actual site. In a way, this would keep processwire handling all the data and requests, and my other "projects" just with a simple script tag. This might all be way too much/over complicated, but I couldn't quite wrap my head around how to achieve it. 

Link to comment
Share on other sites

1 hour ago, louisstephens said:

I have used Pages2JSON before, but I was a bit lost on how to implement what i was thinking.

Same here... I just did my own thing then and created a template for that where I did what I wanted to create.

I build the whole JSON based on the things I needed and it worked out quite well. It was easy to cache as well which was a benefit back at that time.

I neither worked with sub-pages, nor AJAX but with a repeater field that contained a page reference (Occupation - in your case) and a text field (for more details about that if needed).

Therefore I had everything in my object (a product in my case) and could iterate over every item (product) I defined by an URL.

It looked similar to this:

domain.tld/api/{object}/{identifier} 

or

domain.tld/api/product/9876

Maybe I have still access to some of the files and post some snippets here.

 

Just in case... what will be the result of this whole setup. Just to get in the right context.

  • Like 2
Link to comment
Share on other sites

2 minutes ago, wbmnfktr said:

Just in case... what will be the result of this whole setup. Just to get in the right context.

The end result (hopefully) to be able to just include a script tag on a project like:

<script src="https://domain.com/launch?first_name=jim&occupation=builder"></script>

and somehow have access to the field data for the particular job. I could then just append in the data to where I want on the new project.

I was kinda hoping to have processwire really taking care of the posting/get of the data. In the long run, pw could be used to have many other pages not related to people, and I could simply change out the parameters to access the data in new/different projects.

Link to comment
Share on other sites

I challenged myself for something similar in the past but ended that due to my lack of knowledge in JS/AJAX handling.

The thing I mentioned before was done with Angular JS - and a third-party developer involved to do that magic - and I re-created the JSON he needed in PW-page/queries.

If it's ok I will dig through to my archives the following weekend and look for the templates/JSON I created for that project.

It will not be perfect for your things but maybe it gives you an idea somehow.

  • Like 2
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

×
×
  • Create New...