Jump to content

Get all pages from template and output all fields from those pages | SOLVED


Webrobo
 Share

Recommended Posts

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

<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

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...