I want to create my custom block with custom content in Drupal 8,in start I create Block with just simple text on it, and work correctly, my Problem is how can I pass my custom variable to it?
I saw some tutorial about it , my Module name is tcdev
and this is content of .module
file.
function tcdev_theme($existing, $type, $theme, $path) {
return array('tcdev' =>
array(
'variables' => array(
'title' => 'Default title',
'description' => null
),
'template' => 'block--sliderblock'
)
);
}
and my SliderBlock.php
namespace Drupal\tcdev\Plugin\Block;
use Drupal\Core\block\BlockBase;
/**
* Provides a 'SliderBlock' block.
*
* @Block(
* id = "slider_block",
* admin_label = @Translation("Slider Block"),
* )
*/
class SliderBlock extends BlockBase{
/**
* {@inheritdoc}
*/
public function build(){
return array(
'#title' => 'my title ',
'#description' => 'my custom desc'
);
}
}
and finally my template file block--sliderblock.html.twig
<h2>My Custom Block{{ title }}-{{ description }}</h2>
But Result is only "My Custom Block-" . The problem is variables not getting passed to template file,where is my fault?
appreciate any help