I have a basic page, and inside of that basic page I have a view "newsletters". The view "newsletters" has permissions set on it based on role, so only admin and subscribers can see it. How can I display "You must be a subscriber to view this content" on the basic page when the user does not have permissions to view "newsletters".

Currently, if the user cant see "newsletters" my basic page just shows an empty page. I want it to display "You bust be a subscriber to see this content".

I tried creating another view "redirected page" that is only visible to anonymous users but it is not showing up for some reason.

The reason I made a basic page with a view nested inside it is because I wanted users who don't have permission to view the page to still see the link in the menu bar.

  • How is the view placed on the page? As block from the blocks page? As rendered view from a template? As reference? – leymannx Dec 4 '18 at 10:12
  • It is placed as a block from the blocks page. – pootyy Dec 4 '18 at 21:23

You can create a basic Block with your text message and set up Visibility to only Anonymous users, and to show on your basic page.

This way anonymous will see the Block, authenticated will see the Views block.

| improve this answer | |
  • But authenticated users that don't have the subscriber role also won't see it then. Maybe better a block visible to all roles but the subsriber role. – leymannx Dec 4 '18 at 20:06
  • 1
    But, if I have all roles except subscriber, then authenticated users who are subscribers will see that block, and thats not good. – pootyy Dec 4 '18 at 21:23
  • You're both right, I overlooked the roles overlapping. If your user login is setup in a way that doesn't overlap Roles you can setup the basic Block to be visible to Anonymous and all the other roles that aren't Subscribers apart from Authenticated! And set Views to Subscribers and Admin. But if they do overlap try this module: Block Visibility Groups. I haven't tried it but you can probably make a winning combination with the All conditions must pass option. – prkos Dec 5 '18 at 1:34

Not a very elegant solution but a quick solution for your situation. You could add a basic block just below your view block with your "You must be a subscriber to view this content" text

Then in css do:

.myviewblock + .mynewbasicblock {
  display: none;

So that means if your view block is coming out on the page (Which only would if they have permission) then hide your basic block.

But this relies on you keeping those blocks next to each other. And also means the "You must be a subscriber to view this content" content is always on the page but just hidden.

Your alternative could be to instead use a node access module that restricts access to the nodes rather than the view so that the view wouldnt have permissions but the nodes would

| improve this answer | |

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.