Display field of another page


on page one, I want to display field text of page two. The template of page one contains the following code:

<?= page('two')->text() ?>

Calling page one, I get an error page. What did I miss?

What does the error page say? (have you enabled debug mode?)

<?= page('two')->text()->kirbytext() ?>

It says:

Error thrown with message “Call to a member function text() on null”

So page('two') can’t be found. The page() helper fetches a page by ID, so if page two should be in a subfolder, you’d have to call page('subfolder/two'). Also it needs to be published:

The page() helper fetches published pages only. To fetch a draft, you have to use $kirby->page('somepage') .

1 Like

Thank you, it works now! :upside_down_face:

Plus, you should never call a clas method without checking that your object exists:

if ($p = page('subfolder/two')) {
  echo $p->text()->kt();
1 Like