Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Persist aside menu state (minimized or not) in cookie


In

I need to maintain the state of the Aside Menu between requests. I noticed that when the toggle is used to minimize the aside menu a cookie is set.

Is this cookie suposed to restore de minimized state of the toogled menu? is there any way to persist or restore the state of the menu between requests?

thanks!


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Worked great! thank you



Hi,

You can use the KTToggle Events API to safe the toggle state in Cookie and in server side you can access to the Cookie value and toggle the Aside state during the page generation check sidebar_minimize_state cookie value in server side and add data-kt-aside-minimize="on" to the body element and add active class to the toggle element.

Go to src/js/layout/sidebar.js and add


// Private functions
var handleToggle = function () {
// Store sidebar minimize state in cookie
toggleObj.on("kt.toggle.changed", function() {
// In server side check sidebar_minimize_state cookie
// value and add data-kt-app-sidebar-minimize="on"
// attribute to Body tag and "active" class to the toggle button
var date = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); // 30 days from now
var state = toggleObj.isEnabled() ? "on" : "off";

KTCookie.set("sidebar_minimize_state", toggleObj.isEnabled() ? "on" : "off", {expires: date});
});
}


Regards.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(