Twig Drupal 8自定义块(模块)细枝模板文件内容未显示
我已经创建了一个自定义模块并分配了一个细枝模板文件,但它没有显示。 下面是文件和文件夹结构 1.workbuster.module文件的代码如下所示Twig Drupal 8自定义块(模块)细枝模板文件内容未显示,twig,drupal-8,Twig,Drupal 8,我已经创建了一个自定义模块并分配了一个细枝模板文件,但它没有显示。 下面是文件和文件夹结构 1.workbuster.module文件的代码如下所示 <?php /** * Implements hook_theme(). */ function workbuster_theme() { return array( 'block_workbuster' => array( 'variables' => array('title'
<?php
/**
* Implements hook_theme().
*/
function workbuster_theme()
{
return array(
'block_workbuster' => array(
'variables' => array('title' => NULL, 'description' => NULL),
'template' => 'block--workbuster-custom',
),
);
}
<?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'
);
}
}
{#
/**
* @file
* Profile Workbuster block.
*/
#}
<div class="col-sm-3 ws-custom--block">
<h1>{{ title }}</h1>
<p>{{ description }}</p>
</div>[![directory structure][1]][1]
试试:
在WorkbusterBlock.php中,必须按如下方式设置模板:
public function build() {
return array(
'#theme' => 'block__workbuster_custom',
'#title' => 'Workbuster',
'#description' => 'Workbuster'
);
}
在.module中,将模板用作密钥:
function workbuster_theme()
{
return array(
'block__workbuster_custom' => array(
'variables' => array('title' => NULL, 'description' => NULL),
),
);
}
注意:我将模板名称中的连字符(-)替换为下划线(41;请尝试:
在WorkbusterBlock.php中,必须按如下方式设置模板:
public function build() {
return array(
'#theme' => 'block__workbuster_custom',
'#title' => 'Workbuster',
'#description' => 'Workbuster'
);
}
在.module中,将模板用作密钥:
function workbuster_theme()
{
return array(
'block__workbuster_custom' => array(
'variables' => array('title' => NULL, 'description' => NULL),
),
);
}
注意:我将模板名称中的连字符(-)替换为下划线(\)