Array of childrens field-values

Hello,

i added number-fields like “height”, “weight” and “format” to a custom blueprint. now i am trying to get the average, min- and max-value from some of these fields for several templates. my problem is, that i simply do not know how to access that data in kirby to put it in an array.

this is stupid, im sorry. but thanks for your time!
daniel

You could use the pluck() method to create an array of the values from a collection of pages http://getkirby.com/docs/cheatsheet/pages/pluck, e.g.

<?php $heightValues = $page->children()->visible()->pluck('height') ?>

Without knowing exactly from what page collection you want to get these values, I can’t provide any more code, though.

hello!

thank you so much. it is working now: http://www.duffte.com/kirby-2.0.6/articles/i-have-2-dogs

$pages->pluck($field, $split = null, $unique = false)

i had to add $split = all, which was more of a guessing game. isn’t there a better instruction?
i still do not know what this is doing, nor what $unique = xyz does.

If the pages of your collection have the same value stored in the given field, the array returned by pluck() contains the same value several times. By setting $unique to TRUE each value will only appear once.

If you set the ´$unique´ variable to true, every value is added only once (as @flokosiol already explained), which is not what you want.

The $split variable takes a character that servers to split a string, e.g. if your field contains a comma separated list of tags.

So if you wanted to grab all tags from a field but wanted to display every tag only once (=unique) you could write:

<?php $tags = $page->children()->pluck('tags',',', true) ?>

this is beautiful, you guys! thank you!