Jump to content

Find one page (template A) that matches a page reference field in template B and grab data??


hollyvalero
 Share

Recommended Posts


I have 2 templates: Legislation and Events

Legislation template fields:
billnum (eg 1234)
billtype (eg SD, LD, LR)
title  (An Act to Whatever)
clients - a page reference field.


We start with legislation of interest to a specific user who has tagged clients by role for that search string...and sort them by committee

$user_roles_string = $user->roles->find('name!=guest')->implode('|', 'name');
$bills = $pages->find("template=trackerplus, limit=600, client=$user_roles_string, sort=billscmte");


And for each bill, we list clients which is simple since we prequalified them and that field is in this template:

foreach ($bill->client as $c) {
  echo "{$c->title}";
  }
  
  
On the Events template, we have a single page reference field that references the piece of legislation above, with a custom format label that brings in {billtype} {billnum} {title} 

billcalendarbillref

When outputting events, again, I use the user roles string to get the batch.

$user_roles_string = $user->roles->find('name!=guest')->implode('|', 'name');
$events = $pages->find("template=trackercalendarevent, client=$user_roles_string, sort=$cbdate2, limit=600,  cbdate2>=today");

 

For each event I want to create a similar loop to list the clients, but I need to look up the legislation to find a match first - using just the prequalified group of events.


 // if there is a bill reference in the event item
if ($event->billcalendarbillref->id) {    
 // locate the legislation page that matches the billcalendarbillref, get the clients listed, and print them out.
     $items = $pages->find("template=trackerplus,  title=$event->billcalendarbillref->title, limit=1");
          foreach ($items->client as $c) {
          echo "{$c->title}";
           }  

     }


This doesn't seem right...Not sure how to word the match between [template:trackerplus, title] and [template:calendar, billcalendarbillref] ... I thought maybe I should be using 
$items = $page->references(); but then got hopelessly confused...

It's printing blank instead of an error which is a nice change of pace.   ?
What am I doing wrong?
  
  

Link to comment
Share on other sites

22 minutes ago, adrian said:

I'll admit I haven't really read your post - sorry, but I think this might do what you want based on the topic title
https://processwire.com/api/ref/page/references/

I’m looking for examples of how to use the page reference method.  It seems like that’s the way to go. 
 

the page reference field is billcalendarbillref and it’s in the events records found. I need to match that field to the page title of legislation pages using the trackerplus template. 
 

 

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...