I created a custom style-plugin for views, and a corresponding style-template (my-style-template.tpl.php). Similarly, I created a custom row-plugin for views and a corresponding row-template.

The style-template loops through the views-rows, and invokes the row-template on each row:

print $row;

What I am trying to accomplish:

The style-plugin defines certain settings in the $options variable, which gets passed to the style-template. The row-template needs access to some of these settings.

My question:

Is there a way to pass variables from my style-template to my row-template? For example, rather than invoking print $row from the style-template, is there some other way of invoking the row-template, which allows me to pass variables to the row-template?

Thanks very much!

1 Answer 1


You can't pass variables from one template file to another. That is not how things work.

However, a general rule is that every template file has a corresponding preprocess function for creating the variables available in the template.

So, you need to figure out what preprocess functions are being called. The Theme Developer module can help out with this. The theme.inc file lists all of the preprocess functions that the Views module uses.

With those, the standard way of handling things is something like

function mymodule_preprocess_views_view(&$variables) {
  $view = $variables['view'];

Once you have the $view object, you have everything you need. However, you often need to dpm($view) to figure out what is there and/or look at the default preprocess functions.

  • Thank you! When I dpm($view), I see that the style-options are available to the row-template in $view->style_options
    – user606696
    Apr 3, 2013 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.