siteaddict Posted September 25, 2014 Share Posted September 25, 2014 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-0751024 where am i going wrong Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 25, 2014 Share Posted September 25, 2014 (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 September 25, 2014 by Ivan Gretsky 5 Link to comment Share on other sites More sharing options...
siteaddict Posted September 25, 2014 Author Share Posted September 25, 2014 Thank you , i have to say that you guys rock ! 1 Link to comment Share on other sites More sharing options...
Mont Posted October 28, 2014 Share Posted October 28, 2014 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. Link to comment Share on other sites More sharing options...
adrian Posted October 28, 2014 Share Posted October 28, 2014 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'); 1 Link to comment Share on other sites More sharing options...
Mont Posted October 28, 2014 Share Posted October 28, 2014 Thanks Adrian! Worked as soon as I took it out of the <td>'s. Ivan thank you also. Great support here. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted October 29, 2014 Share Posted October 29, 2014 I think you should do it like this: echo "<td>" . $page->promoting_club->title . "</td>"; or echo "<td>{$page->promoting_club->title}</td>"; 1 Link to comment Share on other sites More sharing options...
Mont Posted October 29, 2014 Share Posted October 29, 2014 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. : 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now