Skip to content

Kirby 3.9.8

$field->toPages()

Returns a pages collection from a yaml list of page ids in the field

$field->toPages(string $separator = 'yaml'): Kirby\Cms\Pages

Parameters

Name Type Default Description
$separator string 'yaml' Can be any other separator to split the field value by

Return type

Kirby\Cms\Pages

The toPages() field method only returns published (listed and unlisted) pages, not drafts.

Example

Text file

Title: My page
----
Text: Some text
----
Related:

- blog/article-a
- blog/article-b

Template

<h2>Related articles</h2>
<ul>
  <?php foreach ($page->related()->toPages() as $related): ?>
  <li>
    <a href="<?= $related->url() ?>">
      <?= $related->title() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>