Add a variable to custom views template I have created a view that is grouped by taxonomy term and it displays exactly how I want it. But what I need to do is add the term ID that the view is grouped by as a class, I have the following custom views template created but the term ID is not available as a variable to use.

The template is views-view-unformatted--products.tpl.php where I have printed the title as the class of the wrapper I need to add the term ID instead (the title is actually the term name as this is what the view is grouped by.)

&lt;div class=&lt;?php print '$title)'; ?&gt;&gt;
  &lt;?php if (!empty($title)): ?&gt;
    &lt;h3 class="quick-view-closed"&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
  &lt;?php endif; ?&gt;
  &lt;div class="product-list" hidden&gt;
    &lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
      &lt;div&lt;?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?&gt;&gt;
        &lt;?php print $row; ?&gt;
      &lt;/div&gt;
    &lt;?php endforeach; ?&gt;
  &lt;/div&gt;
&lt;/div&gt;
I haven't time to actually investigate the details of this right now, but if you enable the devel module, put

&lt;?php dpm(get_defined_vars()); ?&gt;


somewhere in your template file somewhere, and then refresh the page twice you will get a list of available variables which you can then click on to expand and drill down into the arrays and objects.

If you still cannot find the tid anywhere to use, try adding the tid as a hidden field to your view, then it will definitely be in there somewhere for you to use.