bootstrap_preprocess_html() stores a reference of $variables['classes_array']

Created on 10 April 2017, almost 8 years ago
Updated 25 April 2017, over 7 years ago

Hi guys

If you are using the bootstrap theme, and if you wish to override the HTML TPL variables using the provided html.vars.php file, some things will not work as expected. For instance, modifying the body classes will result in a mess.

Here is what you can do to reproduce this bug...

  1. Copy the file named html.vars.php from the bootstrap theme's templates/system folder into the templates folder of your custom theme. The content of that file can be seen at the address http://cgit.drupalcode.org/bootstrap/tree/templates/system/html.vars.php...
  2. In our case, we were trying to add a no-js class to the body tag that will be removed by JavaScript afterwards. This can be done in many ways. One possible way is to insert the following code at line 20 of html.vars.php:

      $variables['classes_array'][] = 'no-js';
    
  3. Clear Drupal's cache, then view the source code of the pages. You will notice that the class attribute will be destroyed in an amazing way. See the attached screen capture .
  4. As an alternative, if you try adding a custom class using the patterns used at line 48, 52, and 56 in the switch(){} statement, you will get the same result. You can verify that by inserting the following code between lines 58 and 59
     $variables['body_attributes_array']['class'][] = 'no-js';
    

Interestingly enough, if you forget about the html.vars.php file and directly implement the theme_preprocess_html() hook in your custom theme's templates.php file, then everything will work as expect and the new class will be properly added to the body tag.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇨🇦Canada asiby

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.

Production build 0.71.5 2024