I have to return a custom array from a lazy builder callback and then loop through that array in a Twig template for a custom block. Here is my code so far:
Custom block:
public function build() {
return [
'#theme' => 'custom_theme',
'#variables' => [
'#lazy_builder' => [static::class . '::lazyBuilder', []],
'#create_placeholder' => TRUE,
],
];
}
The callback
public static function lazyBuilder() {
//code above
foreach ($vars as $var) {
$arr[] = [
'title' => $var->getTitle(),
'body' => $var->body->value),
'summary' => $var->summary->value,
];
}
}
sleep(3); // For testing only
return $arr;
}
In my twig template
{% for var in variables %}
<div>{{ var.title }}</div>
{% endfor %}
For each item I want to display its title, body and summary. Everything works fine if I return from the callback an array which has #markup inside, but I need to return my custom array.
If that's not possible it would be also OK if a lazy loaded the whole block not just the content inside it.
Thank you.