Add content type machine name to an attribute in the body tag? I figured this would be easily done in the template_preprocess_html function, but I haven't found a way to do it... yet.

I need to add the content type machine name to a "data-init" attribute in the body tag.  How can this be done exactly?

End result: &lt;body ... data-init="content_type"&gt;
template_preprocess_html should be the right function to start with.

So your code should look like the following:

function mytheme_preprocess_html(&amp;$variables) {
  if ($node = menu_get_object()) {
    $variables['attributes_array']['data-init'][] = drupal_html_class('node-type-' . $node-&gt;type);
  }
}


Make sure to replace mytheme with your custom theme and clear Drupal cache.