Theme change to hide control panel for logged in users
Requirement : Hide the control panel menu by if users have logged in.
In theme we know that by adding <@liferay.control_menu/> macro, we get control panel menu. But sometimes we want it conditional. We don't want control panel menu to appear on the screen by default which can take up header space.
The control panel menu is added by adding following classes on the body tag. These classes are
- has-control-menu
- has-staging-bar (if staging environment is on and the logged in user has staging permission)
- staging-ready (if staging environment is on and the logged in user has staging permission)
- open
Another thing that we need to hide is .control-menu-level-1
The change in theme that you will have to do is updating ftl variable ${css_class}. Write a code to remove the above mentioned body classes from ftl variable ${css_class}
<#assign css_class = css_class?replace("has-control-menu", "") />
<#assign css_class = css_class?replace("has-staging-bar", "") />
<#assign css_class = css_class?replace("staging-ready", "") />
<#assign css_class = css_class?replace("open", "closed")/>
<body class="${css_class}">
and hide .control-menu-level-1
<style type="text/css">
.control-menu-level-1 {
display:none;
}
</style>
To get back control panel menu you can have on/off switch on the theme somewhere which can hide/show the control panel menu through JavaScript.
$( 'body' ).toggleClass( 'has-control-menu' );
if ( $( "body" ).hasClass( "has-control-menu" ) ) {
$( 'body' ).removeClass( 'closed' );
$(".control-menu-level-1").show();
//only if staging environment is ON Start code
if($("#showstagingicon").val() == "true") {
if (! $( 'body' ).hasClass( 'has-staging-bar' ) ) {
$( "body" ).addClass( 'has-staging-bar' );
}
if (! $( 'body' ).hasClass( 'staging-ready' ) ) {
$( "body" ).addClass( 'staging-ready' );
}
}
//only if staging environment is ON End code
} else {
$( "body" ).removeClass( 'has-staging-bar' );
$( 'body' ).removeClass( 'staging-ready' );
$( 'body' ).removeClass( 'open' );
$(".control-menu-level-1").hide();
if (! $( 'body' ).hasClass( 'closed' ) ) {
$( 'body' ).addClass( 'closed' );
}
}

