Reference

Guide

$field->toPages()

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

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

Parameters

Name Type Default Description
$separator string 'yaml'

Can be any other separator to split the field value by

Return type

Pages

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>

Source code

kirby/config/methods.php#L199