Jump to content

access profields table from sibling

Recommended Posts

so I have a Profields Table on a sibling's page, trying to access it from its sibling's page (DUH!) which is $page now, cause that's where I am right now.

I do

    $toc = $page->siblings("template=tableofcontents")->tableofcontents_table;


    $toc = $page->siblings("template=tableofcontents");
    $toc = $toc->tableofcontents_table;

but it just won't work because Call to a member function render() on null

The table clearly is there and clearly is a sibling and its template is as stated and the table also.

Please help me quick, about to throw the computer out the window, thank you.

Share this post

Link to post
Share on other sites
1 hour ago, fruid said:

Please help me quick, about to throw the computer out the window, thank you.

Maybe a sign that it's times for a break 😄.

1 hour ago, fruid said:

$toc = $page->siblings("template=tableofcontents")->tableofcontents_table;

Sometimes it helps to 'speak out your code' to determine if it makes sense. Have a look at that line. tableofcontents_table, I assume, is your Profields Table. Reading that out loud, your code is saying, find me siblings (PLURAL) of this page and get me the value of its (SINGLE) tableofcontents_table field. Doesn't sound right, does it? It's like saying 'find me 10 oranges (PLURAL) and show me its (SINGLE) price. That's wrong. The question would be, which orange's price? We have 10 oranges here! It should read, 'find me 10 oranges (PLURAL) and show me their (PLURAL) prices.  Aha, so, we are dealing with a collection. Any collection has to be iterated (foreach) to get each members individual value. Alternatively, you could ask for the first(), last() or nth() orange to deal with one member only.

OK, so I need to get some sleep too. The docs say this about $page->siblings():


Return this Page’s sibling pages, optionally filtered by a selector.



 Return value

 $toc is a PageArray. 

If you run this in Tracy console: 


d($page->siblings("template=tableofcontents")->tableofcontents_table);// null

You will get the value null, hence your error message since you are doing this null->render().

Now for some unsolicited advice 😁.

  1. TracyDebugger is your best friend.
  2. The table clearly is there and clearly is a sibling and its template is as stated and the table also. Whilst this might be the case, it is best to always check if your selector/query returned something (and its type) before you start working with it.

Hope this helps.

ps: Profields Table has its own VIP support forum, accessible to you if you have a current subscription

  • Like 2

Share this post

Link to post
Share on other sites

OK got it working now, I should always never forget that even though it's just one item, it's still inside an array. 


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 fruid
      I have a profield table and one of its fields is called category.
      I want to use the values of this field and created a unique array which I use for the options-filter.
      $rows = $pages->get('path/to/parent/page')->protable; $categories = new WireArray; foreach ($rows as $r) :     if ($r->category != '') :         $categories->add($r->category);     endif; endforeach; $categories = $categories->unique(); So I loop through the $categories array and output an option field for each.
      This kinda works but not with the pagination. On the second page it would only show the "options" (categories) of those entries that the unfiltered array would show on a second page.
      Where's the problem?
    • By fruid
      Inside the ProFields Table I have one column of type "select" for which I entered several options to choose from. 
      How can I return these options? I mean loop through them to build my markup.
    • By Guy Incognito
      I've created a simple sports league fixture generator in a template called 'League'. Teams are added as page references then a fixture list is created as a ProFields table by hooking page save to add new rows to the table.
      The bit I need help with is that I'm trying to check a fixture doesn't already exist before adding it to the table (e.g. if a new team is added to the league). I'm trying to do this with a PW selector to filter the fixtures table and check whether Team A vs Team B already exists in the table. Then on the next line checking no fixture was found by using count().
      However as soon as I add the selector the script no longer adds any rows to the table. If I take it out, it all works fine (albeit with duplicate fixtures each time the page is saved). I've also tested the selector in a page template and it filters as expected. It's late here (UK)... I'm probably doing something stupid! Any ideas?
      <?php //Hook page save to generate league fixture lists $wire->addHookAfter("Pages::saved(template=league)", function ($event) { //Get which page has been saved $page = $event->arguments(0); $noFixturesAdded = 0; //For each team in league cycle through and add home fixtures foreach ($page->teams_in_league as $teamA) { foreach ($page->teams_in_league as $teamB) { //Check if fixture already exists $existingFixtures = $page->fixtures("team_a=$teamA,team_b=$teamB"); //Check team A is not the same as team B as you can't play yourself //Then add row to fixture table if ($teamB != $teamA && $existingFixtures->count() < 1 ) { $fixture = $page->fixtures->makeBlankItem(); $fixture->team_a = $teamA->id; $fixture->team_b = $teamB->id; $page->fixtures->add($fixture); $noFixturesAdded ++; } } } //Save updates to table $page->save('fixtures'); $message = "League saved. $noFixturesAdded new fixtures were added"; $this->message($message); });  
    • By creativejay
      Just one of those things I often find myself wishing for:
      Could a future update add a "Siblings" list tab (or make a "Children & Siblings" combined tab) to /page/edit/?
      Save + Next is a godsend, but in many cases I need to jump around instead of cycling through. Sometimes I just want to reference how I titled other pages under one parent to keep the naming consistent. Other times I'm deep enough in my page tree that it's a half-dozen or so more clicks than I'd like to get back to where I was.
      So far my workaround is to right-click on the parent's name in the Breadcrumb nav, and open the page tree in a new tab. But when editing a site often has me opening ten or more browser tabs at a time, each one I can cut out is a blessing. 
      Thanks for your consideration!
    • By Reid Bramblett
      OK, after three days of banging my head against this, I turn to the forums.
      I am attempting to apply what would seem to be a rather straightforward filter to a set of results, but am tripping over... something (suspect it's because I continue to have difficulty wrapping my brain around the operation of the ProFields Table field; also, a bit shaky on PageArrays in general).
      I have a links page that includes a "title" field, a "categories" field and a "urls" ProFields Table.
      The urls Table has rows/fields for "poiurl" (the actual full url), "urltext" (the link as I want it to appear), "desc" (an optional description field), and "place" (a dropdown select populated by another page).
      I can get the appropriate links page (filtered by a previously defined "$pcat" category), grab all the urls from the Table, and display them. However, I cannot figure out how to limit those results by a particular field—in this case, "place," as I want to return only those links that match the current page's "place."
      $place=$page->place; $links = $pages->get("template=links, categories=$pcat"); echo "<h4>$links->title</h4> <ul>"; foreach ($links->urls as $u) { if ($u->desc) echo "<li><a href='$u->poiurl'>$u->urltext</a> ($u->desc)</li>"; else echo "<li><a href='$u->poiurl'>$u->urltext</a></li>"; } echo "</ul>"; So, how do I get it to show only the $u results wherein $u->place=$place? 
  • Create New...