Webrobo Posted May 18, 2020 Share Posted May 18, 2020 Hello, I would like to know how do I get all pages from a specific template and output all fields from the pages which uses this template my current attempt to do this: <?php foreach ($pages->find("template=spiel") as $spiele): ?> <tr> <td><?php echo $spiele->title?></td> <td><?php echo $spiele->datum?></td> <td><?php echo $spiele->halle?></td> <td><?php echo $spiele->liga?> | <?php echo $spiele->liga_gruppe?></td> <td><?php echo $spiele->team_a?></td> <td><?php echo $spiele->team_b?></td> <td><?php echo $spiele->ergebnis?></td> <td><?php echo $spiele->kampfgericht_liga?> | <?php echo $spiele->kampfgericht_team?></td> </tr> <?php endforeach; ?> Thanks in advance for help! Link to comment Share on other sites More sharing options...
huseyin Posted May 19, 2020 Share Posted May 19, 2020 Hello, You should have a ; after each echo line. Link to comment Share on other sites More sharing options...
LuisM Posted May 19, 2020 Share Posted May 19, 2020 <div class="row"> <?php foreach($pages->find("template=spiel") as $spiel) : ?> <ul> <?php foreach($spiel as $field => $value) : ?> <li><?= $field ?> <?= $value ?></li> <?php endforeach ?> </ul> <?php endforeach ?> </div> Will output all the template fields in a <ul> for each Page. The caveat is, it will also output system fields. To get only your "custom" fields you could iterate the pages fieldgroup like this <div class="row"> <?php foreach($pages->find('template=spiel') as $spiel) : ?> <ul> <?php foreach($spiel->fieldgroup as $field => $value) : ?> <li><?= $field ?> <?= $value ?></li> <?php endforeach ?> </ul> <?php endforeach ?> </div> Which should output the corresponding Field with Value. To make the code a bit more readable I usually use the <?= $var ?> shorthand for <?php echo $var ?>. Some may like this Syntax, some does not. 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