Accessing page with status DRAFT and its fields from config

Is it possible to access a page with status draft, and its fields, from config ?

For example, in config.php this code…

...
page(/*page id*/)->myfield()
...

…results in a method called on null error, as I assume the page does not exist and cannot be accessed with page().

Is it possible to access the page’s field while the page is in draft?

Thank you

https://getkirby.com/docs/reference/templates/helpers/page: The page() helper fetches published pages only. To fetch a draft, you have to use $kirby->page('somepage') .

In what sort of context are you trying to get the page in the config? In a route?

Great, thank you.

And yes, in the context of a route is that I want to get the page. Why do you ask ?

Thanks again

Just making sure you are not trying to call kirby() in config out of allowed contexts.

1 Like