Fetch table from other page

Hallo,
i have to fetch table from page “aandb” to “c” (templates names). I have read a few topics about fetching, but i have not found working solution for me (i probably doing some wrong)…

Last code is:

`

        					<?php foreach(page()->filterBy('template', 'rzesyibrwi') as $subpage): ?><table class="col-12 col-xl-8">
        						<thead class="pb-2">
        							<tr>
        								<th>1</th><th>2</th><th class="text-center">3</th><th>4</th>
        							</tr>
        						</thead>
        						<tbody>
        						<?php foreach($subpage->zabieg()->toStructure() as $pozycja): ?>
        							<tr>
        								<td class="text-left"><?= $pozycja->name1() ?></td>
        								<td class="text-center"><?= $pozycja->name2() ?></td>
        								<td class="text-center"><?= $pozycja->name3() ?></td>
        								<td class="text-center"><?= $pozycja->name4() ?></td>
        							</tr>
        						<?php endforeach ?>
        						</tbody>
           					</table>
        				<?php endforeach ?>`

Debuger show problem in this line
<?php foreach($subpage->zabieg()->toStructure() as $pozycja): ?>

Please help me :slight_smile:

This first line doesn’t make sense. page() refers to a single page, you cannot filter this. You can pass an URI to the page helper and then fetch the children:

page('projects')->children()`

But I’m not sure what you want to filter here.

Oh, and the information that there is a problem somewhere, is not really that helpful. Could you please post the exact error message?

Pages are not connect together, secnond page is not child first page. Pages are independent.

Debuger said

Error
Call to a member function zabieg() on string

Are these pages A and B direct main pages, i.e. directly subfolders of the content folder? If not, could you please outline the structure of the folders inside the content folder?

You can fetch single pages using the pages()helper. It accepts an array of page URIs as argument.

foreach(pages(['page-a', 'page-b']) as $subpage):
  // code
endforeach;

The error pops up because in your original code $subpage is not a page object.

Assuming these pages are root pages, you can do this:

foreach($pages->filterBy('template', 'rzesyibrwi') as $subpage)
//code
endforeach;

Yes, they are main pages with own folders

Page A - ‘makijaz’ (on this site i want to show table)
Page B - ‘rzesyibrwi’ (on folder on this site i have a txt with table)

foreach(pages(['makijaz', 'rzesyibrwi']) as $subpage):?>
  <?php foreach($subpage->zabieg()->toStructure() as $pozycja): ?>
    <tr>
    <td class="text-left"><?= $pozycja->nazwa() ?></td>
    <td class="text-center"><?= $pozycja->zalozenie() ?></td>
    <td class="text-center"><?= $pozycja->uzupelnienie2() ?></td>
    <td class="text-center"><?= $pozycja->uzupelnienie3() ?></td>
    </tr>
  <?php endforeach ?>
<?php endforeach; ?>

Thanks a lot :slight_smile:

Its work

But if it is only a single page you want to fetch from, then you don’t need the first foreach loop at all.

<?php
// lets check if the page exists before we continue
if($p = page('rzesyibrwi')):
 foreach($p->zabieg()->toStructure() as $pozycja): ?>
    <tr>
    <td class="text-left"><?= $pozycja->nazwa() ?></td>
    <td class="text-center"><?= $pozycja->zalozenie() ?></td>
    <td class="text-center"><?= $pozycja->uzupelnienie2() ?></td>
    <td class="text-center"><?= $pozycja->uzupelnienie3() ?></td>
    </tr>
  <?php endforeach ?>
<?php endif ?>