I am working on a custom slider programmatically. I create a custom module (block_example) and make a block (BlockExample.php) and a twig file (blockexample.html.twig) and also a module file (block_example.module). I want to place some code in twig file and call it in block file.
This is build function from block file (BlockExample.php)
public function build() {
$renderable = [
'#theme' => 'blockexample',
];
return $renderable;
}
This is (blockexample.html.twig) file code
<div class="col-sm-3">
<h1>This is Title</h1>
<p>Description Coming From Twig File</p>
</div>
This is (block_example.module) file code
function block_example_theme() {
return [
'block_example' => [
'variables' => ['test_var' => NULL],
],
];
}
Now main question is how to print twig file in BlockExample.php
'#theme' => 'blockexample',
andreturn ['block_example' => [
. Do you see the difference? One comes with an underscore, and one doesn't. Fix the typo, flush caches a thousand times and tell us if it's working now. – leymannx Jan 27 at 10:45