Check whether a field is structured or not

I’ve written a plugin which exports page content from various fields. By default, it only exports the title and text fields, but I’d like to be able to cycle through the other fields and extract that content accordingly.

My issue is that I need to determine whether a field contains structured YAML data (such as one or more URIs pointing at related pages) or just text (whether it’s a date or email address and so forth.)

Is there built-in way to check whether a field contains structured data (specifically structured list of URIs) or not?

You could get all fields and their types vis the page blueprint() method, see this recipe: Using blueprints in the frontend | Kirby CMS

With this you have access to the field types and can map the field type to different field methods.

Hmmm … that would work if a site actually used blueprints.

However, I have several Kirby sites that do not use the panel, therefore no blueprints.

Of course you could check if $page->somefield()->toStructure() returns a structure Object, but I don’t know if that makes sense to do that for each field, let alone other types of fields.

Don’t think it would be very performant to test each field for each potential field type.

If you have chosen field names wisely, you could probably create a mapping of field names to field types.

Yes, I agree. This didn’t make much sense after I took a closer look at the problem.

I ended up creating a definable array as a config option where the user can specify whether a field contains textual data or a YAML list of related articles or pages.

return [
	'splorp.paperback-export.fields' => ['author' => 'text','posts' => 'related'],

I’m trying to keep the amount of actual content parsing to a minimum and related article fields were specifically something that I wanted to handle.

Thanks again for making me take another look at how I was approaching this.