How to hide side bar in Confluence 5.1.3 for default theme only for some pages in a Space

Hi,

I want to hide side bar in Confluence 5.1.3 for default theme only for some pages in a Space.

I have gone through many links in Answers, but none of them is working for me.

Thanks

Kapil

4 answers

1 accepted

Accepted Answer
1 vote

I've tackled the same issue. The following code should be placed in a HTML macro as it relies on Javascript (specifcially the AJS library built into Confluence). I put all of this into a page in a "resources" space, and then just include that page in the pages I want to hide the left side bar for.

<script type="text/javascript">
//<![CDATA[
AJS.toInit(function(){

  //hide the side bar
  AJS.$('div.ia-splitter-left').hide();
  
  //reset margin of main content area
  AJS.$('div#main').css({'margin-left':'0px'});

  //reset margin of the footer
  AJS.$('#footer').css({'margin-left':'0px'});

});
//]]>
</script>

2 votes
Davin Studer Community Champion Oct 06, 2013

You could also do this with a user macro. I was doing this on our site using an html macro for a while and got tired of copying the JS code, so I made a user macro to do it. Here is what I did..

Macro Name:
collapsenav

Macro Ttle:
Collapse Nav

Description:
Collapse the nav on page access.

Macro Body Processing:
No macro body

Template:
## Macro title: Collapse Nav
## Macro has a body: N
## Developed by: Davin Studer
## Date created: 08/20/2013
## Collapse the nav on page access.

## @noparams

<ac:macro ac:name="html">
<ac:plain-text-body><![CDATA[<script type="text/javascript">
AJS.toInit(function () {
if(AJS.$('.ia-fixed-sidebar.collapsed').length == 0) {
AJS.$('.ia-fixed-sidebar .space-tools-section .expand-collapse-trigger').click();
}
});
</script>]]></ac:plain-text-body>
</ac:macro>

Hi Daven,

Thanks

I tried using your macro, but it is not working for me.

Kapil

Davin Studer Community Champion Oct 07, 2013
Odd. It should work for the default theme. Basically, instead of setting CSS values manually my script is just programmatically clicking the collapse link. Oh well if the other one works then that is probably a good way to go. You may still want to encapsulate it in a user macro so that it is much easier to add to any page you want.

Thanks for this Davin and Charles! I find the user macro option was a good one, however we don't want to change the users side bar settings globally. So I used a combination of both your answer and developed this...

## Macro title: Collapse Nav
## Macro has a body: N
## Developed by: Sam Hall (original version from Davin Studer with some CSS ideas from CharlesH)
## Date created: 26/05/2014
## Collapse the nav on page access, without touching the global user setting.
## @noparams

<script type="text/javascript">//<![CDATA[
AJS.toInit(function () {
  if(AJS.$('.ia-fixed-sidebar.collapsed').length == 0) {
    AJS.$('div.ia-fixed-sidebar').addClass('collapsed').css('width','55px');
    AJS.$('div#main').css({'margin-left':'55px'});
  }
});
//]]></script>

Try calling this instead of setting the CSS, it's a bit more future proof because it uses the Atlassian javascript library instead of relying on specific HTML elements.

 

AJS.Confluence.Sidebar.toggle();

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Confluence

What are your project planning tips?

Hello Community,  Jessica here from the Confluence product marketing team! Today I wanted to get your takes on project planning –– what works, what doesn’t, how do you know if you’re doing it r...

338 views 2 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you