【发布时间】:2016-07-09 16:46:03
【问题描述】:
我的模块中的自定义页面的模板有问题。
我使用hook_theme() 来定义我的树枝文件。当我签入hook_theme_registry_alter() 时,我看到了我的新模板文件,但是当我尝试使用它时它无法正常工作。
我的代码:
文件:first.module
/**
* Implement hook_theme().
*/
function first_theme($existing, $type, $theme, $path) {
return array(
'testtwig' => array(
'template' => 'testtwig',
'variables' => array('test_var' => NULL),
),
);
}
控制器:
/**
* @file
* Contains \Drupal\first\Controller\FirstController.
*/
namespace Drupal\first\Controller;
use Drupal\Core\Controller\ControllerBase;
class FirstController extends ControllerBase {
public function content() {
return array(
'#theme' => 'testtwig',
'#test_var' => t('sss'), //$output,
);
}
}
错误:
模板“modules/custom/first/templates/testtwig.html.twig”不是 已定义(Drupal\Core\Template\Loader\ThemeRegistryLoader:无法 在中找到模板“modules/custom/first/templates/testtwig.html.twig” Drupal 主题注册表。)。
【问题讨论】:
-
你得到的树枝文件是什么名字,你把它放在哪里?
-
Twig 文件名:testtwig.html.twig 我把这个文件放在
modules/custom/first/templates -
我发现哪里有问题:) 所以我有另一个同名文件。感谢您的帮助