【发布时间】:2019-10-11 11:53:35
【问题描述】:
我创建了一个自定义模块并分配了一个树枝模板文件,但它没有显示。 以下是文件和文件夹结构
1.workbuster.module文件代码如下
<?php
/**
* Implements hook_theme().
*/
function workbuster_theme()
{
return array(
'block_workbuster' => array(
'variables' => array('title' => NULL, 'description' => NULL),
'template' => 'block--workbuster-custom',
),
);
}
2。 WorkbusterBlock 文件的代码如下
<?php
/**
* @file
*/
namespace Drupal\workbuster\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'Workbuster' Block
* @Block(
* id = "block_workbuster",
* admin_label = @Translation("Workbuster block"),
* )
*/
class WorkbusterBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return array(
'#title' => 'Workbuster',
'#description' => 'Workbuster'
);
}
}
3. block--workbuster-custom.html.twig 文件的代码如下
{#
/**
* @file
* Profile Workbuster block.
*/
#}
<div class="col-sm-3 ws-custom--block">
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>[![directory structure][1]][1]
【问题讨论】: