Hey there…
currently i try to build a block that gets its Informations from another template
so… this is my start:
<?php
$resourcesfile = $site->page('res-wohnungen');
$wohneinheiten = $resourcesfile->wohneinheiten()->toStructure()->sortBy('house', 'asc');
?>
if i want some of the data, i iterate through the structure like this:
<?php foreach ($wohneinheiten as $wohneinheit): ?>
<tr>
<td><?= $wohneinheit->house(); ?></td>
<td><?= $wohneinheit->floor(); ?></td>
<td><?= $wohneinheit->flat(); ?></td>
<td><?= $wohneinheit->accessibility(); ?></td>
<td><?= $wohneinheit->wbs(); ?></td>
</tr>
<?php endforeach ?>
thats how it goes… but i want it to be a little bit more flexible… i want to iterate each “wohneinheit” without manuel-adding fields and sections of the res-wohnungen-blueprint (like house() or flat()).
so i can start searching for them like this:
$tablekeys = $wohneinheiten->first()->content()->keys();
but how to use the resulting array now?
Array
(
[0] => house
[1] => floor
[2] => flat
[3] => accessibility
[4] => wbs
}
but how to get a $wohneinheit->house(); without knowing that house() exists but knowing that there is the array $tablekeys?
the following syntax is crap… but it maybe shows, what i am talking about:
<?php foreach ($wohneinheiten as $wohneinheit): ?>
<tr>
<?php foreach ($tablekeys as $tablekey): ?>
<td><?= $wohneinheit->$tablekey(); ?></td> // <-- what for "$tablekey()"???
<?php endforeach ?>
</tr>
<?php endforeach ?>
the idea behind this: i want to generate tables with this block… but it is not always known, which columns exist. the block should be usable for pages with different columns/sections/data.