Jump to content

Stuck Trying To Get Select Fields To Output in Template file


siteaddict
 Share

Recommended Posts

Your select fields are most likely page fields. They hold reference to another page. Those numbers which you see are page ids. To output fields of the referenced pages you should do something like:

<p> <?php echo $page->Battery_Manufacturer->title; ?></p>

Here is a nice video tutorial about this type of fields. But you probably already know it if you're using it.

Edited by Ivan Gretsky
  • Like 5
Link to comment
Share on other sites

  • 1 month later...

I am using page fields and was getting the page_id also.  I tried Ivan's suggestion and it returned the page id number and ->title.  It also adds another page id when I change the selection. (example below)

The code I am using is:

<table>

 <thead>
   <tr>
  
     <th>Rider Name</th>
     <th>Promoting Club</th>
     <th>Class</th>
     <th>M.O.T.A. Pt</th>
 
   </tr>
 </thead>
 <tbody>
   <?php
     echo "<tr>";
     echo "<td>$page->title</td>";
     echo "<td>$page->promoting_club->title</td>";
     echo "<td>$page->Classes->title</td>";
     echo "<td>$page->mota_pts</td>";
     echo "</tr>";
   ?>
 </tbody>
</table>

Am I using the page field in the wrong context?  I do not want to use it like the example video.  I want to select a class that the rider is in e.g. Expert, Advanced, Sportsman.....  and display it in the template.  

Screen_shot.png

Link to comment
Share on other sites

Hi Mont,

Page fields are arrays so if there is only one expected result:

echo $page->promoting_club->first()->title;

Or if you want to list them all out, you can foreach:

foreach($page->Classes as $class) echo $class->title;

or you can use implode (https://processwire.com/talk/topic/5098-new-wirearray-api-additions-on-dev/):

echo $page->Classes->implode(', ', 'title'); 
  • Like 1
Link to comment
Share on other sites

Ivan, thank you for your great advice.  It worked but I had to remember to add what Adrian had said.  I also changed first to last because I wanted the latest Class the rider rode.  Here is the code I ended up using, I used both examples Ivan gave to see if they worked.

    	 <table>
 <thead>
   <tr>
  
     <th>Rider Name</th>
     <th>Promoting Club</th>
     <th>Class</th>
     <th>M.O.T.A. Pt</th>
	
   </tr>
 </thead>
 <tbody>
   <?php
     echo "<tr>";
     echo "<td>$page->title</td>";
     echo "<td>".$page->promoting_club->last()->title."</td>";
     echo "<td>" . $page->Classes->last()->title. "</td>";
     echo "<td>$page->mota_pts</td>";
     echo "</tr>";
   ?>
 </tbody>
</table>

The support on this forum is great and truly appreciated.  O0:rolleyes: ::):rolleyes:

  • Like 1
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...