Pre-render callback: Renders #browsers into #prefix and #suffix.
$elements: A render array with a '#browsers' property. The '#browsers' property can contain any or all of the following keys:
Examples:
The passed-in element with markup for conditional comments potentially added to '#prefix' and '#suffix'.
function drupal_pre_render_conditional_comments($elements) {
$browsers = isset($elements['#browsers']) ? $elements['#browsers'] : array();
$browsers += array(
'IE' => TRUE,
'!IE' => TRUE,
);
// If rendering in all browsers, no need for conditional comments.
if ($browsers['IE'] === TRUE && $browsers['!IE']) {
return $elements;
}
// Determine the conditional comment expression for Internet Explorer to
// evaluate.
if ($browsers['IE'] === TRUE) {
$expression = 'IE';
}
elseif ($browsers['IE'] === FALSE) {
$expression = '!IE';
}
else {
$expression = $browsers['IE'];
}
// Wrap the element's potentially existing #prefix and #suffix properties with
// conditional comment markup. The conditional comment expression is evaluated
// by Internet Explorer only. To control the rendering by other browsers,
// either the "downlevel-hidden" or "downlevel-revealed" technique must be
// used. See http://en.wikipedia.org/wiki/Conditional_comment for details.
$elements += array(
'#prefix' => '',
'#suffix' => '',
);
if (!$browsers['!IE']) {
// "downlevel-hidden".
$elements['#prefix'] = "\n<!--[if {$expression}]>\n" . $elements['#prefix'];
$elements['#suffix'] .= "<![endif]-->\n";
}
else {
// "downlevel-revealed".
$elements['#prefix'] = "\n<!--[if {$expression}]><!-->\n" . $elements['#prefix'];
$elements['#suffix'] .= "<!--<![endif]-->\n";
}
return $elements;
}