MSP01 Posted April 22, 2022 Share Posted April 22, 2022 I have a template that is used on many pages, but some of those pages need to be disabled from guest users. An addHookBefore('Page::render'...) works fine for throwing a 404 if someone actually gets on the page. But is there a way to disable those pages in site navigation, and any other place where they might be visible in one fell swoop? I thought that addHookAfter('Page::viewable'...) could work, but I haven't been able to make it do anything at all. Basically I'd love to have a way to disable those pages without going through every single $pages->find() and similar piece of code where those pages might crop up. Using access rights would be the easy way, but I cannot change the template and most of those pages are public. Link to comment Share on other sites More sharing options...
horst Posted April 22, 2022 Share Posted April 22, 2022 Whats about using public state for those that can get listed in menus etc, and hidden state for the others? 1 Link to comment Share on other sites More sharing options...
Robin S Posted April 22, 2022 Share Posted April 22, 2022 8 hours ago, MSP01 said: but I cannot change the template Why is that? Why not create a copy of the template (Setup > Templates > Add New > Copy fields from another template) that has access control enabled and then edit the pages to use that template? And the template file can just consist of: include './your_other_template_file.php'; 1 Link to comment Share on other sites More sharing options...
MSP01 Posted April 25, 2022 Author Share Posted April 25, 2022 @horst This could work, but I'd rather keep things very literal. A check box that says "don't show this page to certain people" is more clear than setting them hidden. @Robin S I could of course do that, but I'd really rather not. There are a lot of these pages, and there's a lot going on under the hood. I'd have to change code all over the place and it's what I'm trying to avoid in the first place. Sorry if it seems I'm trying to find the most difficult way to do a simple thing. If there's no easy fix via hook, I'll just do it manually in the code. ? It's also possible there will be need to hide pages from more than one group while showing it to other groups in the future and Horst's suggestion wouldn't work in that case. Neither would the template. Or at least I wouldn't want to create a new template every single time something like that came up. It seems like a very heavy way of doing something that should be handled within a page itself. Link to comment Share on other sites More sharing options...
horst Posted April 25, 2022 Share Posted April 25, 2022 On 4/22/2022 at 11:47 PM, Robin S said: Why is that? Why not create a copy of the template (Setup > Templates > Add New > Copy fields from another template) that has access control enabled and then edit the pages to use that template? Hi Robin, I think one can do that a bit simpler, at least I always use it this way: 1) I'm not hundred percent sure, but maybe there is difference between cloning the whole template compared against only duplicate the fields. (Cloning definitely includes all settings under family, files, advanced, etc) 2) And this saves the creation of an extra template file. All in all very useful when I want to use something like a single controller file, that calls different view files upon the template names. ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now