Hiding pagestypes from the sitetree in SilverStripe 4
Sometimes when you have a ModelAdmin for creating pages you really don't want to clutter the SiteTree with all this pages. You might want the admin to edit and add pages through the ModelAdmin. Well, how do you hide them from the SiteTree then?
There are a few options. In earlier versions of SilverStripe you had to use the Lumberjack module to “cut” down the sitetree….. get it?
In the most recent versions of SilverStripe you can use Hierachy::hide_from_cms_tree. This is a property intended to be used on the parent pages. You supply an array of class names and those will not be shown in the cms. If you want to hide this pages from the frontend SiteTree::Menu() function you can use Hierachy::hide_from_hierachy instead.
I however ran into an issue where my customer wanted to hide root pages created by a ModelAdmin. And through some tinkering and help from the community it seems that the easiest way is to hide the root pages with CSS. Now if we take a look at the SiteTree through the browser's web webdeveloper extension we see that SilverStripe already puts in the classname as a css class:
In this case we can target class-App_Partner_PartnerPage, which is the namespace of our class to a css file in app/css/hide_partner.css:
.cms-tree.jstree li.class-App_Partner_PartnerPage{ display: none; }
Edit your config.yml to include this css file in the backend:
SilverStripe\Admin\LeftAndMain: extra_requirements_css: - app/css/hide_partner.css
And expose the file in composer.json to be copied over to public/resources:
"Expose": [ "app/css" ]
Lastly just do a dev/build?flush to flush the config.
Post your comment
Comments
Tran Tai 24/06/2020 5:10am (5 years ago)
awesome, thank you
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments