Jump to content

force template state :: must be hidden!


Stefan G. Eberl
 Share

Recommended Posts

Hello there,

I have a template only to get a simple structure in my page tree. (for example: a category-site)

the sites from this template must be hidden...

if they are not hidden, you can see them in my nav-menu!

Now - my question:

Is there any way to set a permanent hidden-state to the template?
 

Why I need this:

...because there are some admin-noobs... :-)  I think they will forget to set the page hidden.
 

Thanks a lot.

Stefan

Link to comment
Share on other sites

I don't think there is any way to set a page status locked to hidden without also preventing editing, either by user access permissions, or the locked status option.

However, it is easy to prevent the pages of a template from being displayed in your menu. If you are using Soma's Markup Simple Navigation module:

$treeMenu = $modules->get("MarkupSimpleNavigation"); 
echo $treeMenu->render(array("selector" => "template!=category-site));

If you are rolling your own menu, then you can still use the template!=category-site in your selector which populates the page array for your menu.

Hope that helps. If you need a more specific example, show us the code you are using and we'll show you what needs to be done.

Link to comment
Share on other sites

Now - my question:

Is there any way to set a permanent hidden-state to the template?

Try adding this to the top of your /site/templates/admin.php, after the opening <?php tag: 

$pages->addHook('saveReady', null, 'makePageHidden'); 
function makePageHidden(HookEvent $event) {
  $page = $event->arguments(0); 
  if($page->template != 'category-site') return; // replace 'category-site' with your template name
  if(!$page->is(Page::statusHidden)) $page->addStatus(Page::statusHidden); 
} 
  • Like 5
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...