Frage

How do I preprocess $variables specific to a custom.tpl.php?

I have a hook_preprocess_node to implement theme_hook_suggestions as follow

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

And a function to return HTML for the node_contentType__viewMode

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

  //build output markups ....

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

Now let's say that I want a preprocess function specifically targetting the viewMode theme above, how do I do it?

I have tried

function customeTheme_preprocess_node__article__full(&$variables) {}

but it didn't seem to work.

War es hilfreich?

Lösung 2

Big help from scronide. In case anyone is looking, here is how I solved it. On your 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);
  }
 }
}

You can now add the preprocess function conformed to the format specified above.

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

You can extend this technique to also preprocess a specific display_id.

Andere Tipps

I haven't tested this but you could simply call your own custom preprocess functions from the main one:

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'];
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top