I am displaying a block on all /user pages, that will show all upcoming events, and the staff that have been assigned to certain roles at that event.

For example...

Manager: Jake

Bar Staff: Mike, Fred, Jim

Sound Tech: James, Bill

What I want to achieve, is for every instance of a users name to be highlighted in that view, if they are logged in. So, go to Bills user page, and all "Bill" entries have an "active" class applied to them. Then, go to Mikes user page, and all "Mike" entries are given the "active" class etc.

Usually, I would name a template field for the view field views-view-field--field-manager.tpl.php and do a comparison with the current user page title, which is the current users name...


$title = drupal_get_title();

if ($title == $output) {
  $class = "active";


<span class="<?php if(isset($class)) { print $class; } ?>"><?php print $output; ?></span>

But this is affecting the whole field, which is no good when you have multiple users referenced in the field.

Is there a way to target individual multiple results in a field with a tpl file?

1 Answer 1


This was actually much easier than I anticipated.

Of course, by default, every user name is a link, and for the user name to be highlighted on each users page, it meant that the link could automatically be given an active class as the current page.

Problem solved.

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.