I have a preprocess_html
function that gets an array of google fonts and adds them as an html class. I have it partially working but if say I have three fonts, only the last one gets into <html class="">
element. Here is what I have so far:
if ($families) {
foreach ($families as $fontString) {
$fontclass = preg_replace('/[^\d\w]+/', '-', strtolower($fontString));
$element = array(
'#tag' => 'html',
'#attributes' => array(
'class' => $fontclass,
),
);
drupal_add_html_head($element, 'google_fonts');
}
}
In the example above, I have these fonts in my site:
- Montserrat
- Actor
- Pathway Gothic One
... but only the last one renders in my html class as:
<html class="pathway-gothic-one-regular">
If I do a dsm within my function:
dsm(drupal_get_html_head());
I see all three fonts print out in separate boxes as
<html class="actor-regular" />
<html class="montserrat-regular" />
<html class="pathway-gothic-one-regular" />
so I think I am not getting something right here.
Note, if I change my code to a body class array, it works as expected. e.g.
if ($families) {
foreach ($families as $fontString) {
$vars['classes_array'][] = preg_replace('/[^\d\w]+/', '-', strtolower($fontString));
}
}
yields:
<body class="actor-regular montserrat-regular pathway-gothic-one-regular">
From a build standpoint, I'd like to keep these classes one level higher than body so that's why I'd like them to be in <html class="">
.