Skip to content

Instantly share code, notes, and snippets.

@pascalduez
Created December 1, 2011 16:18
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save pascalduez/1417914 to your computer and use it in GitHub Desktop.
Save pascalduez/1417914 to your computer and use it in GitHub Desktop.
Drupal 7 — HTML5 html.tpl.php
<!DOCTYPE html>
<html<?php print $html_attributes; ?>>
<head>
<?php print $head; ?>
<title><?php print $head_title; ?></title>
<?php print $styles; ?>
<?php print $scripts; ?>
</head>
<body<?php print $body_attributes;?>>
<?php print $page_top; ?>
<?php print $page; ?>
<?php print $page_bottom; ?>
</body>
</html>
<?php
/**
* Implements hook_preprocess_html().
*/
function THEMENAME_preprocess_html(&$vars) {
$vars['html_attributes_array'] = array();
$vars['body_attributes_array'] = array();
// HTML element attributes.
$vars['html_attributes_array']['lang'] = $vars['language']->language;
$vars['html_attributes_array']['dir'] = $vars['language']->dir;
// Adds RDF namespace prefix bindings in the form of an RDFa 1.1 prefix
// attribute inside the html element.
if (function_exists('rdf_get_namespaces')) {
$vars['rdf'] = new stdClass;
foreach (rdf_get_namespaces() as $prefix => $uri) {
$vars['rdf']->prefix .= $prefix . ': ' . $uri . "\n";
}
$vars['html_attributes_array']['prefix'] = $vars['rdf']->prefix;
}
// BODY element attributes.
$vars['body_attributes_array']['class'] = $vars['classes_array'];
$vars['body_attributes_array'] += $vars['attributes_array'];
$vars['attributes_array'] = '';
}
/**
* Implements hook_process_html().
*/
function THEMENAME_process_html(&$vars) {
// Flatten out html_attributes and body_attributes.
$vars['html_attributes'] = drupal_attributes($vars['html_attributes_array']);
$vars['body_attributes'] = drupal_attributes($vars['body_attributes_array']);
}
/**
* Implements hook_html_head_alter().
*/
function THEMENAME_html_head_alter(&$head_elements) {
// Simplify the meta charset declaration.
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8',
);
}
@pascalduez
Copy link
Author

Sort of a backport from Drupal 8 RDFa / HTML5 doctype cleaning.
See http://dgo.to/1077566 and http://dgo.to/1164926

@danny-englander
Copy link

Thanks for this, I just implemented these snippets on my D7 site. I see you are checking rdf_get_namespaces, that essentially is checking if the RDF module is enabled if I understand that right?

@pascalduez
Copy link
Author

I see you are checking rdf_get_namespaces, that essentially is checking if the RDF module is enabled if I understand that right?

Late reply sorry. But yes, if RDF module is not enabled then just do nothing, and prevent an error as well :-)
We could have used module_exists() but I generally avoid DB queries in theme when possible.

@pascalduez
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment