Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put a html tag conditional in jade?

In jade, I want to put in a html tag conditional as per this method, which puts in

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->

at the top of a html file.

I tried

//[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]
//[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]
//[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]
//[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]
  head
    ...

but jade ignores the html tag, and doesn't write in the end </html> tag. This is invalid html, and results in IE not displaying anything at all.

Is there any way of doing it?

I'm thinking I'll just use a javascript solution if there isn't a way.

like image 448
zlog Avatar asked Oct 13 '11 16:10

zlog


3 Answers

This method works, with the closing html tag:

!!! 5
//if lt IE 7
    <html class="no-js lt-ie9 lt-ie8 lt-ie7">
//if IE 7
    <html class="no-js lt-ie9 lt-ie8">
//if IE 8
    <html class="no-js lt-ie9">
// [if gt IE 8] <!
html(class="no-js", lang="en")
    // <![endif]
    head
        title= title

    body!= body

from: https://gist.github.com/kmiyashiro/1140425#comment-675550

Update:

As pointed out by kumar-harsh this behaviour has now been depreciated, if you need this functionality you now should use regular html:

<!--[if IE]>
  <html class="ie">
<![endif]-->
<![if !IE]>
  <html class="not-ie">
<![endif]>
</html>

from: https://github.com/visionmedia/jade/issues/1345?source=cc#issuecomment-31920732

like image 102
Stephen Avatar answered Oct 21 '22 04:10

Stephen


This is what you're looking for, and it will also give the closing html tag.

!!! 5
//[if lt IE 7]><html lang="en" class="no-js oldie lt-ie9 lt-ie8 lt-ie7"><![endif]
//[if IE 7]><html lang="en" class="no-js oldie lt-ie9 lt-ie8"><![endif]
//[if IE 8]><html lang="en" class="no-js oldie lt-ie9"><![endif]
//[if gt IE 8]><!
html(class='no-js', lang='en')
  //<![endif]
  head
like image 27
Stacey Cordoni Avatar answered Oct 21 '22 04:10

Stacey Cordoni


Simply use this syntax, mind the different indentation:

!!! 5
| <!--[if lt IE 7]> <html class="ie6 oldie" lang="en"> <![endif]-->
| <!--[if IE 7]>    <html class="ie7 oldie" lang="en"> <![endif]-->
| <!--[if IE 8]>    <html class="ie8 oldie" lang="en"> <![endif]-->
| <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
head
  …
like image 36
Frederic Avatar answered Oct 21 '22 05:10

Frederic