Passing a custom variable from preprocess view to a template file 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(&amp;$vars) {
    $view = $vars['view'];

    $currentpath = current_path();
    $path_alias = drupal_lookup_path('alias',$currentpath);

    // define the custom variable
    $vars['mycustomvariable'] = '';

    if ($view-&gt;name == 'mycustomviewname') {

        foreach($view-&gt;result as $key =&gt; $result) {
            $tid = $result-&gt;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:

&lt;?php print $mycustomvariable; ?&gt;


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.
I'm not fully sure what I'm going to tell you is completely true, it is just my experience of how Views works.

From what I know, Every preprocess function has access to a specific output template file. As an example variables of template_preprocess_views_view_fields are available in views-view-fields--AnyThingElse.tpl.php template file, so the domain access of variables of template_preprocess_views_view_fields is views-view-fields--AnyThingElse.tpl.php.

In Theme Information there are three levels of output styles:


Display output
Style output
Row style output


The views-view-list--mycustomviewname--block_1.tpl.php is a TPL file in the second level (Style output) but I guess the mycustomtheme_preprocess_views_view domain of access of its variables is in the first level (Display output) TPL files.

To make sure, select one of the TPL files from Display output and check if the variable is set in there.