代码之家  ›  专栏  ›  技术社区  ›  Kevin

drupal theme()函数和自定义模板

  •  2
  • Kevin  · 技术社区  · 15 年前

    我有一个从Web服务调用返回数据的自定义模块。它来自一个XML响应,我正在将其转换为一个数组。

    一旦我有了阵列,我会:

    $output = theme('search_srs_results', $data);
    return $output;
    

    但我得到了一个白屏。没有apache/php/watchdog错误。

    我以前在另一个模块中做过,没有任何困难。定义了主题挂钩,并指向模板文件,传递$data参数。如果在返回$output之前转储它,则为空。

    $data在主题化之前肯定有一个填充的数组。

    如果我做主题(“item_list”,$data);,它将呈现,没有白色屏幕。

    我尝试再次阅读hook_theme and theme()上的文档,但我似乎没有做错什么。

    主题功能如下:

    /**
     * Implementation of hook_theme()
     */
    
    function srs_finder_theme() {
      return array(
        'search_srs_results' => array(
          'template' => 'srs-finder-results',
          'arguments' => array('data' => null),
        ),
      );
    }
    
    /**
     * Implementation of hook_preprocess()
     */
    
    function srs_finder_preprocess_search_srs_results(&$vars) {
      $data = $vars['data'];
    }
    

    缺少什么?

    1 回复  |  直到 15 年前
        1
  •  3
  •   Sid Kshatriya    15 年前

    hook_preprocess() $data srs-finder-results.tpl.php theme('src_src_results', $data) hook_theme()

    src_finder theme_search_srs_results template