Jump to content

Get Page Reference Title


Recommended Posts


Im using the following structure

Location 1
  - Employee
     -- John Doe
     --Jane Doe

  - Department
    -- Confused Department
    --Even More Confused

Each employee is assigned a department which I am using a select page reference field. I need to be able to print the title of the department.

I am using the following to output my fields, but for the "department" field, I can only get it to print the id.  I am assuming this is because its only a page reference field as to why it will not print the title.  Any tips are appreciated

$employees = $page->find("template=profile");
         foreach ($employees as $employee) { 
          echo '<tr>';
             echo "<td>{$employee->first_name}</td>";
             echo "<td>{$employee->last_name}</td>";
             echo "<td>{$employee->job_title}</td>";
             echo "<td>{$employee->department}</td>";
             echo "<td><a href='{$employee->url}'>Profile</a></td>";
             echo '</tr>';

I have tried 

echo "<td>{$employee->department->title}</td>";

with no luck

Edited by RJay
Link to comment
Share on other sites

Okay, so I figured it out sorta.

I had to change the field type to "Single page (Page) or empty page (NullPage) when none selected" instead of the multiple pages. Also if I tried the single page boolean, I threw this error "Trying to get property of non-object".

Maybe someone can educate me today :) on how this would work or if it could work with the multiple page array?

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

  • Create New...