How to style my custom Fivestar field? After having solved How to calculate the average Fivestar rating correctly?, I have a computed field Average score that displays the average score of a node. I sometimes want to display this field in a View as a rating (e.g. 4.2/5) and add some more markup to it. For the moment, I have different templates of the form views-view-field--MY-VIEW--field-average-score.tpl.php with the same code:

&lt;?php $rating = round(($output/100) * 5, 1); ?&gt;
&lt;span&gt;
  &lt;span class="star"&gt;&lt;/span&gt;&lt;span&gt;&lt;?php print $rating . '/5'; ?&gt;&lt;/span&gt;
&lt;/span&gt;


Having all these duplicate templates seems silly to me. Is there a way to only have one and somehow point out which Average score fields should be styled accordingly? Simply using views-view-field--field-average-score.tpl.php is not what I want, since I don't always want to style Average score like this.
Then you can do it like this:

Use view-field--field-average-score.tpl.php which will affect all views that have this field, but we can add an if statement to target the views you only want the special markup. 

Ex: In here we check if it has view_name with block_1 OR view_name_2 with block_1

&lt;?php if (($view-&gt;name == 'view_name' &amp;&amp; $view-&gt;current_display == 'block_1') || ($view-&gt;name == 'view_name_2' &amp;&amp; $view-&gt;current_display == 'block_1'): ?&gt;
&lt;?php $rating = round(($output/100) * 5, 1); ?&gt;
&lt;span&gt;
  &lt;span class="star"&gt;&lt;/span&gt;&lt;span&gt;&lt;?php print $rating . '/5'; ?&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;?php else: ?&gt;
&lt;?php print $output; ?&gt;
&lt;?php endif; ?&gt;


In case you are wondering, current_display is the machine name

The $view-&gt;current_display check is optional. This is so it only affects a certain Display of block/page that is inside your view. 

So for line 1, you could use this instead: 

&lt;?php if ($view-&gt;name == 'view_name' || $view-&gt;name == 'view_name_2'): ?&gt;


If you want to affect all blocks/pages that are inside these 2 views.