$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
This method modifies the existing $field
object it is applied to and returns it again.
The toPages()
field method only returns published (listed and unlisted) pages, not drafts.
Examples
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>