# Check whether a field is structured or not

**URL:** <https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 18, 2022, 5:47pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021 "2022-07-18T17:47:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![splorp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/splorp/32/29_2.png) [@splorp](https://forum.getkirby.com/u/splorp)\
**Post date:** [July 18, 2022, 5:47pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021/1 "2022-07-18T17:47:41Z")

</div>

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](https://getkirby.com/docs/cookbook/content/related-articles)) 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?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 18, 2022, 7:08pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021/2 "2022-07-18T19:08:08Z")

</div>

You could get all fields and their types vis the page blueprint() method, see this recipe: [Using blueprints in the frontend | Kirby CMS](https://getkirby.com/docs/cookbook/templating/blueprints-in-frontend)

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

---

<div class="post-metadata">

**Author:** ![splorp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/splorp/32/29_2.png) [@splorp](https://forum.getkirby.com/u/splorp)\
**Post date:** [July 18, 2022, 8:57pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021/3 "2022-07-18T20:57:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 18, 2022, 9:51pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021/4 "2022-07-18T21:51:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![splorp](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/splorp/32/29_2.png) [@splorp](https://forum.getkirby.com/u/splorp)\
**Post date:** [July 29, 2022, 9:36pm UTC](https://forum.getkirby.com/t/check-whether-a-field-is-structured-or-not/26021/5 "2022-07-29T21:36:45Z")

</div>

> [@texnixe](#):
>
> Don’t think it would be very performant to test each field for each potential field type.

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

> [@texnixe](#):
>
> If you have chosen field names wisely, you could probably create a mapping of field names to field types.

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.

```php
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.
