Whats the best way to switch the order of sidebar and content blocks on breakpoints?

Created on 12 May 2021, over 3 years ago
Updated 9 March 2023, almost 2 years ago

Problem/Motivation

When I collapse my Drupal down to mobile width the sidebar first block is displayed ahead of content. I cant see a way to set the order through the UI and I cant find any contrib modules to assist.

Steps to reproduce

Enable theme
Populate sidebar and content with renderable items (anything)
Observe sidebar-first, content, column order on desktop
Resize the browser window to mobile dimensions.
Note (i) the rows switch to columns as expected and (ii) the sidebar is placed ahead of the main content.

Proposed resolution

Ideally add some UI settings to control the order and visibility of sidebars relative to content

Remaining tasks

TBD

User interface changes

API changes

Data model changes

✨ Feature request
Status

Closed: works as designed

Version

5.5

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Syntapse

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States gscerb

    drupal/bootstrap_barrio 5.5.9
    This is my global.js file. It doesn't display a reordering for the first column on a small device.

    /**
    * @file
    * Global utilities.
    *
    */
    (function ($, Drupal) {

    'use strict';

    Drupal.behaviors.my_theme = {
    attach: function (context, settings) {

    }
    };

    })(jQuery, Drupal);

    let MOBILE_BREAKPOINT = 692;
    let width = 0, prevWidth = 0;

    function initWindowResize() {
    $( window ).resize(function() {
    let width = $( window ).width();
    // console.log("window resized: ", width);

    if ((width < MOBILE_BREAKPOINT) && (prevWidth >= MOBILE_BREAKPOINT)) {
    console.log("switching to mobile");
    $('.sidebar_first').removeClass('order-first');
    $('.main-content').addClass('order-first');
    }

    if ((width > MOBILE_BREAKPOINT) && (prevWidth <= MOBILE_BREAKPOINT)) {
    console.log("switching to desktop");
    $('.main-content').removeClass('order-first');
    $('.sidebar_first').addClass('order-first');
    }

    prevWidth = width;
    });
    }

  • πŸ‡΅πŸ‡ͺPeru hatuhay Lima

    I suggest to alter region classes on your sub theme preprocess, applying Bootstrap layout classes

  • πŸ‡ΊπŸ‡ΈUnited States lenlamberg

    I wanted to display one column for small devices, with content first (full width); then display content on the left and first sidebar to the right for tablets, and three columns with content in the center for larger screens. I created a subtheme, with a new page.html.twig template, and included the following code block:
    {% block content %}

    {{ page.breadcrumb }}


    {{ page.content }}



    {% if page.sidebar_first %}

    {{ page.sidebar_first }}

    {% endif %}
    {% if page.sidebar_second %}

    {{ page.sidebar_second }}

    {% endif %}

    {% endblock %}

Production build 0.71.5 2024