drupal 8 use node_view_multiple as list in twig template
Searched for:
- drupal 8 use node_view_multiple as list in twig template
- remove items in array key starts with # drupal 8
- php filter array remove items matching key pattern
- drupal 8 #prerender
a trick to remove a set of known keys: https://www.php.net/manual/en/function.array-filter.php#87912
But actually, better, array filter itself has a flag to use keys for the filtering now, https://www.php.net/manual/en/function.array-filter.php
Anyway, after the truly awful forced rendering stuff, which has got to be undone sometime, comes the nifty filtering bit:
$raw_programs = node_view_multiple(array_map($map, $result->getResultItems()), 'teaser');
// NOT a hack i like, but it's the only way i can get these nodes to not just render as empty shells
// (really! it printed the template without any of the text). This seems to be related to prerender:
// https://www.drupal.org/project/drupal/issues/2099131
// https://www.drupal.org/project/drupal/issues/2151459
render($raw_programs);
$programs = array_filter($raw_programs, function ($key) { return substr($key, 0, 1) !== '#'; }, ARRAY_FILTER_USE_KEY);