# All fields in array?

**URL:** <https://forum.getkirby.com/t/all-fields-in-array/956>\
**Category:** Questions\
**Tags:** v2\
**Created:** [April 30, 2015, 1:19pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956 "2015-04-30T13:19:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [April 30, 2015, 1:19pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/1 "2015-04-30T13:19:16Z")

</div>

Hi,  
how can I output all fields of an page in an array?  
I found pluck(). But this is not exactly what I want. I want all from one item and not one field from all items.

Kind

---

<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:** [April 30, 2015, 1:25pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/2 "2015-04-30T13:25:08Z")

</div>

```auto
<?php
$c = $page->content();
foreach ($c as $key => $value) {
  if ($key == "fields") {
    foreach ($value as $field) {
      echo $field . ": " . $page->$field() . "<br/>";
    }
  }
}
?>

```

originally copied from this post [http://getkirby.com/forum/general/20141007/how-to-loop-through-all-fields-on-a-page](http://getkirby.com/forum/general/20141007/how-to-loop-through-all-fields-on-a-page), not tested

---

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [April 30, 2015, 1:50pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/3 "2015-04-30T13:50:58Z")

</div>

Hey,  
thanks for it!  
As first I tested the output from $page-\>content(); but there I got the error „Catchable fatal error: Object of class Content could not be converted to string in…“. Whats going wrong here?  
Here is my code:

```
<?php foreach($page->children() as $section): ?>
<section class="text list">
	<?php foreach($section->children() as $book): ?>
	<article class="list-item">
	<div><?php echo $book->content(); ?></div>
		<?php if($book->hasImages()) : ?>
…
```

---

<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:** [April 30, 2015, 1:53pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/4 "2015-04-30T13:53:26Z")

</div>

`$book->content()` returns an object, you cannot echo that …

---

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [April 30, 2015, 2:50pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/5 "2015-04-30T14:50:50Z")

</div>

Hi,  
your posted code works perfekt for me. Thanks!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [April 30, 2015, 3:04pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/6 "2015-04-30T15:04:42Z")

</div>

You can get an array of the whole page array with

```php
$page->content()->toArray()

```

or the whole page object (also including e.g. uid, slug, intendedTemplate) with

```php
$page->toArray()

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:17pm UTC](https://forum.getkirby.com/t/all-fields-in-array/956/7 "2025-02-06T17:17:27Z")

</div>

Archived on February 6, 2025, 5:17pm UTC


