Jump to content

Recommended Posts

Posted

Hi, can you guys help a beginner with a problem..

On my template (profile_page) i have a dropdown (page reference) where i can choose a sports team (team_page) that is related to that profile which is also its parent. Then on my Competition1 page (competition_page) I have page reference field (profiles) a dropdown that i want to display only profiles that has choose a specific sports team (template=team_page) the page parent to be specific.

Structure/Template

Sports_team1 (team_page)

     Profile1 (profile_page)
     Profile2 (profile_page)
     Profile3 (profile_page)
     Competition1 (competition_page)

 

ready.php

<?php 
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'profiles') {
    $relative = $page->parent->name; $event->return = $event->pages->find("template=profile_page, sports_team=$relative");
  }
});
?>

This returns with no results in the dropdown. If i remove sports_team=$relative then it displays all profiles that have profile_page as template, so it works almost. But i will have more sports teams so this is just an example. I only want to display the profiles that has choosen the parent team on there profile page in admin not front end.

I hope i was able to explain it so you guys can understand a little bit. Need some help please! /Thanks

 

 

Posted

I don't completely understand your structure, but you are passing in only a name (not a complete path), so ProcessWire has no way of knowing where in your page tree the $relative page is located. If you use the ID instead, it should work:

$relative = $page->parent->id;
$event->return = $event->pages->find("template=profile_page, sports_team=$relative");

 

Posted

image.png.37eaef77cac6be0b7d0f99f49fd30c5a.png

Thanks for your reply but still no results... if i remove

, sports_team=$relative

It will show all profile names so i works almost.

If i put that string on the actual page either id or name it will show just those profile names but on the admin maybe there is something different you have to write im clueless..

 

 

Posted

I managed to find a solution in another topic.

 

<?php
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'profiles') {
    $page = $event->arguments('page');
    $event->return = $event->pages->find("template=profile_page, team_page={$page->parent}");
  }
});
?>

 

Posted

@Flashmaster82 That's the same thing. {$page->parent} evaluates to the parent page's ID. The difference is that you're now using "team_page" instead of "sports_team". The query needs to match the name of the field you're using to select the sports team on the profile_page, so make sure to use the correct field names.

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
×
×
  • Create New...