当Drupal 8首次出现时,这对我来说无疑是有用的。然而,这似乎不再起作用,我得到一个错误。 Drupal文档总是很可怕所以没有解决方案。
custom.module
<?php
function custom_theme() {
$theme['home_page'] = [
'variables' => ['name' => NULL],
'template' => 'home_page'
];
return $theme;
}
function custom_menu(){
$items = array();
$items['admin/config/system/custom'] = array(
'title' => 'Custom',
'description' => 'Configuration Custom',
'route_name' => 'custom.settings'
);
return $items;
}
custom.routing.yml
custom.home:
path: /home
defaults:
_controller: Drupal\custom\Controller\RoutingController::home
requirements:
_permission: 'access content'
SRC /控制器/ RoutingController.php
<?php
namespace Drupal\custom\Controller;
class RoutingController {
public function home(){
return array(
'#title' => 'Home',
'#theme' => 'home_page'
);
}
}
home_page.html.twig
<main>
<!-- some markup -->
</main>
答案 0 :(得分:0)
您的控制器没有扩展基本控制器类问题一 试试这个
namespace Drupal\custom\Controller;
use Drupal\Core\Controller\ControllerBase;
class RoutingController extends ControllerBase{
public function home(){
return array(
'#title' => 'Home',
'#theme' => 'home_page'
);
}
}
<强> home_page.html.twig 强>
<main>
<!-- some markup -->
{{ content }}
</main>
还尝试使用路径
扩展主题钩子'path' => drupal_get_path('module', 'custom') . '/templates',
将模板twig文件放在module / templates文件夹中