What's the opposite of $page->toArray?

Hello,

i have a array with all page data (as the $page->toArray does it).
How can i convert it back to a page object and render it?

https://getkirby.com/docs/cheatsheet/page/to-array

What is your use case? You can’t create virtual page objects, the page has to exist in the file system. So the page object is simply $page or page('somepage').

Still the “changes/diff stuff”… i have a page with “content blocks” (kirby modules) and want to render both blocks: the actual one (from file) and the saved/old version one… from an array.

Maybe i can “inject” the data from the “old-array” into the “new-pageObject” if a user want to see the old content…hmm.

I think you can extend the page class for this purpose.

Hm, don’t know how this works. Maybe @jenstornell can help me out?

I need a page extension to set stuff rather than get it… $module->content->fields->text = “1”; want work.

S.

Not sure if it will solve your problem, but maybe you can use this: https://github.com/jenstornell/kirby-secrets/wiki/Page-value-manipulation

1 Like

Yes, that’s what I referred to.

Ok, i’ll take a look into the code.

Thank you both!

How do i pass a array like yours from outside the class? … call’ new Test’ with a set of fields i want to change?

Instead of using a predefined array, I’d overwrite the constructor to accept a data array …

public function __construct($parent, $dirname, $data = []) {

  //...
  $this->data = $data;

}

(then change all instances of array to data in the __call method)

And instantiate the new object like this:

$new = new Test($page->parent(), $page->dirname(), $data);
1 Like