1

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: <body ... data-init="content_type">

1 Answer 1

4

template_preprocess_html should be the right function to start with.

So your code should look like the following:

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

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.