Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(