0

If I want to hide or show a DOM element, say a button that can show further information because the logged in user is a manager, how can I do that in Drupal 8? Do I need to create separate pages for each type of user role?

I saw this but wasn't sure if it was the same thing I was asking,

How can I change page elements (menu, blocks, etc) based on a chosen 'audience' link?

2

If you want to make a button only available to users who are admins, put this property in the form element:

'#access' => \Drupal::currentUser()->hasPermission('access administration pages'),
| improve this answer | |
  • I know this is old, but does this mean put this between php tags in my html page? I'm not sure how to to implement this in Drupal 8. – johnny May 1 '17 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.