How to hide/show view based on field's value? Problem: I have a user directory that anyone can access, with pages for each user. However, there is a view (that's a block) with personal info that I only want shown to the user who's page it is, or users with an admin role. They are not the authors of the page. I know how to fix the admin role issue, and how to get the username using php, but not how to get the field containing the username of the person who owns the page. I can't use Views PHP, just Views. Thanks!

EDIT: I tried doing something where in the view's header I had

if ($current_user == "[field_user_name]") { ?&gt;


Then in the footer of the view:

&lt;?php } ?&gt;


But that hasn't worked.
Okay, I think I got it now. Already tested.


Override the view's template (Tutorial)
Include global $user; somewhere in the first php tag.
Use an if statement: &lt;?php if (strip_tags($view-&gt;render_field("YOUR_FIELD", $id)) == $user-&gt;name): ?&gt; with YOUR_FIELD as the field's replacement pattern without brackets. (remember the &lt;?php endif; ?&gt;)


Sample view template (for unformated view display):

&lt;?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
global $user;
?&gt;
&lt;?php if (!empty($title)): ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;?php if (strip_tags($view-&gt;render_field("title", $id)) == $user-&gt;name): ?&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 endif; ?&gt;
&lt;?php endforeach; ?&gt;