I can use $page->content()->toArray()
to get the page’s fields in an array. However, structure fields are still in YAML format (strings). Is there a way to get them parsed with the Kirby API? And I don’t mean with yaml::decode
because you can’t know which field is a structure and which is just a string. You’d have to dig in the blueprint to find out.
I’ve made this method:
public function parseContent ($content, $fieldBlueprints) {
$data = [];
foreach ($fieldBlueprints as $key => $blueprint) {
$field = $content->$key();
if ($blueprint['type'] === 'structure') {
$data[$key] = $field->yaml();
} else {
$data[$key] = $field->value();
}
}
return $data;
}
and then you call that with:
$this->parseContent($page->content(), $page->blueprint()->fields());
It works, but my question is - is there a way to do that with the Kirby API? I mean, at some point, Kirby has to parse that YAML when it renders the page, so that functionality must be somewhere there. If it’s not, then perhaps I should propose a $page->parsedContent()
method.