没有找到Drupal 8自定义模块"主题钩子"

时间:2018-02-24 12:55:12

标签: drupal module drupal-8 drupal-themes

我正在为Drupal 8.4.4构建一个自定义模块,并且没有从块中检测到hook_theme。我收到一条错误消息,上面写着"没有找到主题钩子gardentheme"。 如果我卸载模块并再次安装它,它可以正常工作,但是一旦我清除了缓存,它就不再能找到theme_hook了。

我注意到die()并退出;清除缓存后,我不会对我的.module文件执行任何操作,我觉得在清除缓存后,.module不再运行了。

我的模块文件名为garden.module

<?php

/**
 * @file
 *
 */


/**
 * Implements hook_theme()
*/ 
function garden_theme($existing, $type, $theme, $path){ 

 return array('gardentheme' =>
  array(
    'variables' => array(
      'description' => NULL
      ),
     )
   );
  }

我的块放在src / Plugin / Block / GardenScheduleBlock.php

 <?php
 namespace Drupal\garden\Plugin\Block;

 use Drupal\Core\Block\BlockBase;

 /**
  * Provides a 'GardenSchedule' Block.
  *
  * @Block(
  *   id = "garden_schedule_block",
  *   admin_label = @Translation("Garden Schedule"),
  *   category = @Translation("Garden Schedule_Category"),
  * )
  */
  class GardenScheduleBlock extends BlockBase {

   /**
    * {@inheritdoc}
   */
   public function build() {
     return array(
       '#theme' => 'gardentheme',
       '#description' => "description test"
       );
   }

  }

提前感谢任何提示。

1 个答案:

答案 0 :(得分:0)

public function build() {
$renderable = [
  '#theme' => 'my_template',
  '#test_var' => 'test variable',
];

return $renderable;

}

尝试

相关问题