1

如何预处理特定于 custom.tpl.php 的 $variables?

我有一个 hook_preprocess_node 来实现 theme_hook_suggestions 如下

function customtheme_preprocess_node(&$variables) {
  $variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];
}

以及为 node_ contentType __viewMode返回 HTML 的函数

function customTheme_node__article__full($variables) {
  $output = '';

  //build output markups ....

  $output .= render($variables['content']);
  return $output;
}

现在假设我想要一个专门针对上面 viewMode 主题的预处理函数,我该怎么做?

我努力了

function customeTheme_preprocess_node__article__full(&$variables) {}

但它似乎没有用。

4

2 回答 2

1

我没有对此进行测试,但您可以简单地从主函数调用您自己的自定义预处理函数:

function customtheme_preprocess_node(&$variables) {
  $preprocess_mode = __FUNCTION__ . '__' . $variables['type'] . '__' . $variables['view_mode'];
  if (function_exists($preprocess_mode)) {
    $preprocess_mode($variables);
  }
  $variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__' . $variables['view_mode'];
}
于 2014-04-02T20:29:11.023 回答
0

来自 scronide 的巨大帮助。如果有人在看,这就是我解决它的方法。在您的template.php,

function mytheme_preprocess_views_view(&$variables) {
 if(isset($variables['view']->name)) {
  $function = 'mytheme_preprocess_views_view__' . $variables['view']->name;
  if(function_exists($function)){
   $function($variables);
  }
 }
}

您现在可以添加符合上述格式的预处理函数。

function mytheme_preprocess_views_view__related_items(&$variables){
//add your preprocess statements here ...
}

您可以扩展此技术以预处理特定的 display_id。

于 2014-04-08T15:55:07.287 回答