Jump to content
louisstephens

Is this even a viable way to go about this?

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. 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By LAPS
      I opened a new wishlist topic on the PW forum for this and in the meantime I ask to the community looking for a reasonable solution.
       
      Using the PageTable field, is there a way to un-restrict the creation of pages under a given parent template page (or as page children if no parent for items is selected)? That is, is there a way to allow the selection of the parent page dynamically / on the fly during page creation via the PageTable field?
    • By LAPS
      I'm using the PW PageTable field extensively and I think an improvement to it could be made regarding the ability to choose the page parent where the page created via PageTable will reside.
      Say you have a PageTable field set like this:
      Edit Field: page_table_field > Details >
      Select one or more templates for items
      > template_one
      > template_two
      > template_three
      Select a parent for items
      > parent_template
      Actually, you can only create pages under the parent_template page (or as page child if no parent for items is selected).
      BTW I am looking for reasons about this limitation.
      What about allowing to choose on the fly where the pages created via PageTable will reside? that is, having the possibility to choose dynamically under which parent page to create the pages?
      Actually, one could overcome to this by creating multiple appropriately set PageTable fields, one PageTable field per PageTable parent for items, but this is unsustainable (?) when you want to create a lot using PageTable…
      By allowing to choose dynamically / on the fly the parent page during page creation via the PageTable field would open up a wider usage of PageTable.
      What do you think about?
       
      @ryan @Robin S
    • By ngrmm
      My clients wants a modal to show up on every page. But when a user clicks inside the modal -> a session-cookie is set and the modal gets a class.
      // user clicks on modal button $('.modal_button').click(function(){ // 1. set PW session cookie // 2. toggle class $('.modal').toggleClass('off'); }); I know how to set a cookie on page-load via PW-API. But the click on the modal button does not force a page-load. So i have to set the cookie through javascript. Is there a way to do that?
    • By VeiJari
      Hello,
      I'm trying to create a page via api and populate values to it. I can populate everything except user pages to a page reference array.
      Code: 
      $dataUsers = $data->project->users; foreach($dataUsers as $dataUser) { $newProject->projectUsers->add(wire()->pages->find('template=user, id=' . $dataUser->id)); } I'm receiving my data via JSON.
      Is there something I'm missing?
      Thanks for help
    • By SwimToWin
      I want to add a dependent SELECT field on my template page that lists pages from a parent "sub-page" in the current parent node.
      On /product1/page I have the field "photo" which is a SELECT field.
      I want the SELECT to list pages from /ROOTPARENT/photos.
      The idea is that I can reuse the same photo in many places - but only need to keep it update it once under /product1/photos.
      My page structure looks like so:
      /product1/page /product1/photos/photo3 (template=photos) /product2/photos/photo9 I have tried adding these Selector Strings on the Field (Setup -> Fields -> PHOTO -> Input tab -> Selectable Pages field group -> Selector String):
      parent=/product1/page, template=photos, sort=name WORKS (but only on children of current product). parent=page.rootParent ... parent=$page.rootParent ... parent=$page.rootParent parent=$parent ... parent=$parent1 When using a SELECT Input Field Type, the editing pages gives the fatal error "Unrecognized operator: $". parent=parent ... parent=. Returns an empty list How might I find child pages from the current "/product1/photos/ page"?
      Your inputs are appreciated. Thanks.
×
×
  • Create New...