I am preprocessing a view in order to create a custom variable and then pass it to a view template file.
I have added the following code to the template.php file:
function mycustomtheme_preprocess_views_view(&$vars) {
$view = $vars['view'];
$currentpath = current_path();
$path_alias = drupal_lookup_path('alias',$currentpath);
// define the custom variable
$vars['mycustomvariable'] = '';
if ($view->name == 'mycustomviewname') {
foreach($view->result as $key => $result) {
$tid = $result->tid; // get the taxonomy term's ID
$termpath = drupal_get_path_alias('taxonomy/term/' . $tid); // term's path
// if the current path is same to the one of the term
if ($termpath == $path_alias) {
// give a value to the custom variable
$vars['mycustomvariable'] = 'blablabla';
}
}
}
}
Then in the views-view-list--mycustomviewname--block_1.tpl.php file, I try to print the variable like this:
<?php print $mycustomvariable; ?>
But I am getting the error:
Notice: Undefined variable: mycustomvariable in include() (line 18 of views-view-list--mycustomviewname--block_1.tpl.php)
I have spent a considerable amount of time on this issue and used dpm and print_r to print out variables, arrays and objects but I cannot seem to find solution to this issue.
Any help would be appreciated. Thank you in advance.
if ($termpath == $path_alias)
condition holds?dpm($vars)
right after$vars['mycustomvariable'] = 'blablabla';
gives "mycustomvariable (String, 9 characters ) blablabla". So, I am guessing the variable is correctly assigned to the custom variable. So, is my way of trying to print the variable inside the template file wrong or am I missing something else? Thank you for your help.