In my Footer-Template i will fetch the content of specified page. How can is get this content?

I tried with find
<?php if ($page->find('footer')->text()->isNotEmpty()): ?>
<?= ->find('footer')->text()->kt() ?>
<?php endif ?>

Not quite right, $page->('footer') is looking for a page called footer. That may or may not be the name of the page you are trying to find.

This will do it, assuming the page is called “your-page” and the field name is “text”. However, if this page ever got deleted or the url changed, this line would stop working.

<?= $page->find('your-page')->text()->kt() ?>

On a side note, it is better to put things like footer text inside the site.yml. Giving it it’s own page means it gets a URL and Google will be able to see it and index it. It might show in your sitemap if you have one.

You can use the page helper here:

if ($p = page('path-to-page') {
  echo $p->text()->kt();

$page->find('somepage') will only work if somepage is a child of $page (which is usually the current page). That doesn’t make sense in the footer context.

Duh… didnt even spot that… im half asleep… you can do this to find it at the top level, but again, check the page exists before trying to use it…

<?= $site->find('your-page')->text()->kt() ?>

I think we are going to have to give each 5 minutes so we dont clash posts… i was still typing… again!


nice. thanks for this help.
now i tried the next thingy. a structure field :frowning:

maybe i didn’t yet understand the syntax, so i am getting a syntax error for the ending foreach – hmm.

<?php foreach ($site->find('your-page')->social()->toStructure() as $social) ?>
   <?= $social->descr() ?>
     <a href="<?= $social->url() ?>"><?= $social->platform() ?></a>
<?php endforeach ?>

The code looks ok, but if the page you are trying to find doesn’t exist…you get an error. What exactly does the error message say?

The Kirby CMS Debugger reports:

syntax error, unexpected 'endforeach' (T_ENDFOREACH), expecting end of file

Ah, the colon is missing in this line, I’m so blind…

<?php foreach ($site->find('your-page')->social()->toStructure() as $social) : ?>

But as said above, please make sure that the page exist first.

<?php if ($page = $site->find('your-page') : ?>
    <?php foreach ($page->social()->toStructure() as $social) : ?>
    <!-- your code here -->
    <?php endforeach ?>
<?php endif ?>

And ideally, you add another check if your structure field has elements to prevent rendering empty tags…

oh yeah! very nice. thanks a lot. yes the page exist, and can not be deleted.
but the check if thing and the check for empty fields i do implement.