Drupal show / hide fields in view

11,227

Solution 1

You can create two identical Displays (within the same view) and override the field settings and access settings in each of them. For example, in the first display show the fields you only want a certain role to see, and set the access control setting to that role. In the second display, remove the unwanted fields and set the access control to the corresponding role.

Start by creating the most restrictive display first and then the least restrictive one.

Solution 2

I liked this answer, but in my case the field is dependent on the argument and I would need to create a new display for each argument (which isn't practical).

I installed the Views Custom Field module and used this code for the field:

<?php
if(user_access("some permission string here"))
{
  print "Your field value here";
}
?>

Solution 3

Click advanced, theeming, find the field and make a _.tpl.php file for it, then in the file you will see:

print $output;

Change this to:

if (user_access('administer nodes')) {
    print $output;
}

Or whatever the permission is you are checking against.

Solution 4

I think you have to try module Field Permissions

Share:
11,227
SteD
Author by

SteD

( •_•) ( •_•)&gt;⌐■-■ (⌐■_■) SOreadytohelp

Updated on June 04, 2022

Comments

  • SteD
    SteD almost 2 years

    I would like to show / hide certain fields in my Drupal view accordingly to the user role.

    Provided I can only have this view to work with, how can I achieve this programmatically or there's some settings that I am not aware of in Drupal.

    P/S: I am aware of the access settings under basic settings in View but that would restrict access to the whole view, not field level.