templates/layout: Prevent flashing of collapsed sidebar on page load
When sidebar is in collpased mode, it was previously flashing from expanded to collapsed when loading a page as its state was changed using javascript.
So prefer to use a cookie describing sidebar state that can be read server side from django and injected in templates, this way the sidebar is ensured to be in correct state in HTML code on page load.
Migrated from D8153 (view on Phabricator)