1/ Background: One-pager project => The backend (panel) allows the editor to specify page data (‘elements’ = ‘
ele’) for rendering. The
home.php template loops through all elements and calls the related ‘intendedTemplate’ snippets, which works well:
<?php foreach ($pages->listed() as $section): ?> <?php if ($section and $section->isNotEmpty()): ?> <?php snippet('ele.' . $section->intendedTemplate() . '.snippet', ['data' => $section]) ?> <?php endif ?> <?php endforeach ?>
2/ Special case: at additional places in the html, code needs to be inserted, beside the looped elements.
3/ filterBy: For the insertion of the dedicated code, I use the ‘filterBy’ method to specify the intended snippet for code insertion, but the method does not work as expected by me.
4/ my template:
<?php snippet('ele.socialmediapanel.snippet', ['data' => $pages->listed()->filterBy('intendedTemplate', 'socialmediapanel')]) ?>
Surrounding html selectors are suppressed by the comment editor
<?php var_dump($data) ?>
/site/blueprints/pages contains a ‘
socialmediapanel.yml’ with section definitions.
/content/4_sm contains a
'socialmediapanel.txt’ with the page data.
5/ Problem: the snippet call works, but the filterBy() method seems not to return a page object to the
$data variable (respectively I cannot access the page data) while the
foreach loop does return a page object (respectively I can access the page data).
In the snippet, the $data variables are dumped. The
filterBy() induced dump does not contain page data, while the loop induced dump does.
I checked the Filtering compendium and understand that
filterBy() might be tricky (e.g. example “Filter by
pages field”). I can share var_dump() results, if requested.
What is my mistake respectively how can I filter a dedicated page using
filterBy() and get the intended page data?
Thank you for your help!