Jump to content

Stuck Trying To Get Select Fields To Output in Template file


Recommended Posts

Posted

I have made a template that has select fields and i'm trying to ouput in my template file but i just get a number ?

my template file code

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

gives me

Battery-Type-075

1024

where am i going wrong :-)

Posted (edited)

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
  • 1 month later...
Posted

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

Posted

Thanks Adrian!  Worked as soon as I took it out of the <td>'s.  Ivan thank you also.  Great support here.

  • Like 1
Posted

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

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