0

Is there a way to toggle the left/sidebar admin menu altogether, like VSCode or SublimeText?

It'd be great to only display the sections & entries on certain occasions. This comes in handy especially if there are several columns selected in a particular section.

Thanks in advance!

1 Answer 1

1

There's no built-in way to do this, but you can build that functionality into a module. This will inject some CSS to all CP requests that will remove the sidebar and make the page container span the entire page:

/** @var craft\web\View $view */
$view = Craft::$app->getView();

if (Craft::$app->getRequest()->getIsCpRequest()) {
    $view->registerCss(<<<'CSS'
        #global-sidebar {
            display: none;
        }
        body.ltr #page-container {
            padding-left: 0;
        }
        #main-content {
            width: 100vw;
        }
    CSS);
}

(Will need some adjustments if you need to support rtl languages.)

Now this alone is not particularly useful, but you can make it more dynamic depending on your requirements:

  • To limit this to particular user groups, you can use the Control Panel Body Classes plugin and scope the CSS to a particular user group class.
  • If you want to have an on/off toggle, you can inject some JavaScript (see View::registerJs) that adds a floating button to toggle the above CSS on click.
2
  • 1
    That sounds good. I think I can get away with injecting CSS or simply using the plugin you suggested. Much appreciate the reply! Aug 3 at 12:37
  • @JaeBarclay If this solved your issue, would you mind marking my answer as accepted? Thanks.
    – MoritzLost
    Aug 3 at 12:49

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.