Conditional class on  element a la boilerplate This might be a totally mundane question, but I hope not.

I want to add conditional classes onto the &lt;html&gt; element of my theme like boilerplate. I'd like to keep things neat and not complicate my page.tpl.php.

&lt;?php
  $htmlvar = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="' .
    $language-&gt;language . '" lang="' .
    $language-&gt;language . '" dir="'. $language-&gt;dir .'"';
?&gt;

&lt;!--[if lt IE 7 ]&gt; &lt;html class="ie6" &lt;?php print $htmlvar ?&gt;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7 ]&gt;    &lt;html class="ie7" &lt;?php print $htmlvar ?&gt;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8 ]&gt;    &lt;html class="ie8" &lt;?php print $htmlvar ?&gt;&gt; &lt;![endif]--&gt;
&lt;!--[if (gte IE 9)|!(IE)]&gt;&lt;!--&gt; &lt;html &lt;?php print $htmlvar ?&gt;&gt; &lt;!--&lt;![endif]--&gt;


Reactions? Suggestions? Taunts?
There isn't really a great way to do this: Drupal 7 modified drupal_add_css() to make adding conditional CSS possible outside the template file, but not for arbitrary HTML.  Drupal 6 doesn't have anything.

In Drupal 6, and for arbitrary conditional HTML, you either need to add the markup directly  to page.tpl.php, or you could create a variable in your theme's implementation of template_preprocess_page() that contains the relevant markup as a string:

Drupal 7

function foo_preprocess_html(&amp;$variables) {
  $htmlvar = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="' .
    $variables['language']-&gt;language . '" lang="' .
    $variables['language']-&gt;language . '" dir="'. $language-&gt;dir .'"';

  $variables['conditional_html'] = '&lt;!--[if lt IE 7 ]&gt; &lt;html class="ie6"' . $htmlvar . '&gt; &lt;![endif]--&gt;';
  // Concactenate the rest of the conditional HTML here
}


Then add $condtional_html to the appropriate place in html.tpl.php.

Drupal 6

function foo_preprocess_page(&amp;$variables) {
  $htmlvar = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="' .
    $variables['language']-&gt;language . '" lang="' .
    $variables['language']-&gt;language . '" dir="'. $language-&gt;dir .'"';

  $variables['conditional_html'] = '&lt;!--[if lt IE 7 ]&gt; &lt;html class="ie6"' . $htmlvar . '&gt; &lt;![endif]--&gt;';
  // Concactenate the rest of the conditional HTML here
}


Then add $condtional_html to the appropriate place in page.tpl.php.



If you're interested in Drupal 7's conditional CSS handling, you can see Bartik's implementation of template_preprocess_html() for an example:

function bartik_preprocess_html(&amp;$variables) {
  // ...

  // Add conditional stylesheets for IE
  drupal_add_css(path_to_theme() . '/css/ie.css', array('group' =&gt; CSS_THEME, 'browsers' =&gt; array('IE' =&gt; 'lte IE 7', '!IE' =&gt; FALSE), 'preprocess' =&gt; FALSE));
  drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' =&gt; CSS_THEME, 'browsers' =&gt; array('IE' =&gt; 'IE 6', '!IE' =&gt; FALSE), 'preprocess' =&gt; FALSE));
}