Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
HTML5 Boilerplate Conditional comments in Jade
!!! 5
//if lt IE 7
html(class="no-js ie6 oldie", lang="en")
//if IE 7
html(class="no-js ie7 oldie", lang="en")
//if IE 8
html(class="no-js ie8 oldie", lang="en")
// [if gt IE 8] <!
html(class="no-js", lang="en")
// <![endif]
head
title= title
body!= body
@davidmarkclements

This comment has been minimized.

Show comment Hide comment
@davidmarkclements

davidmarkclements Apr 14, 2012

thanks so much for making this available, I couldn't seem to get the indenting right or something and all the html tags weren't wrapping the content, they we're just immediately closing. Anyway, cheers.

thanks so much for making this available, I couldn't seem to get the indenting right or something and all the html tags weren't wrapping the content, they we're just immediately closing. Anyway, cheers.

@guioconnor

This comment has been minimized.

Show comment Hide comment
@guioconnor

guioconnor Jul 25, 2012

Thanks for sharing this, however, this doesn't seem to work because the html tags within the conditional comments are empty and they will close before the header opens. This code validates, of course, because the code inside the comments will be ignored but effectively, in IE the page it's outside the element

This is the generated code:

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

Thanks for sharing this, however, this doesn't seem to work because the html tags within the conditional comments are empty and they will close before the header opens. This code validates, of course, because the code inside the comments will be ignored but effectively, in IE the page it's outside the element

This is the generated code:

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

@davidmarkclements

This comment has been minimized.

Show comment Hide comment
@davidmarkclements

davidmarkclements Jul 25, 2012

hey gui, check out https://github.com/robrighter/node-boilerplate/blob/master/templates/views/layout.jade i use that one and it works fine (although I update mine to current h5b - eg lt-ie8 class instead of ie8 class

hey gui, check out https://github.com/robrighter/node-boilerplate/blob/master/templates/views/layout.jade i use that one and it works fine (although I update mine to current h5b - eg lt-ie8 class instead of ie8 class

@guioconnor

This comment has been minimized.

Show comment Hide comment
@guioconnor

guioconnor Jul 25, 2012

Hi David, I've C+P the code on that link into a jade template and this is how it renders:

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

As you can see there's a </html> tag at the end of each conditional clause. Of course it will work on every non IE browser since the code is commented out and I'm not sure how IE copes with the problem, but in theory that would place the <head> and <body> as siblings of the <html> plus you have an unmatched </html> at the end.

Hi David, I've C+P the code on that link into a jade template and this is how it renders:

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

As you can see there's a </html> tag at the end of each conditional clause. Of course it will work on every non IE browser since the code is commented out and I'm not sure how IE copes with the problem, but in theory that would place the <head> and <body> as siblings of the <html> plus you have an unmatched </html> at the end.

@kmiyashiro

This comment has been minimized.

Show comment Hide comment
@kmiyashiro

kmiyashiro Jul 25, 2012

I'm not at a computer totest this, but jade must have changed something in its engine since this was/is working fine for me with no extra closing HTML tags. I'll test it out.

Owner

kmiyashiro commented Jul 25, 2012

I'm not at a computer totest this, but jade must have changed something in its engine since this was/is working fine for me with no extra closing HTML tags. I'll test it out.

@davidmarkclements

This comment has been minimized.

Show comment Hide comment
@davidmarkclements

davidmarkclements Jul 25, 2012

@guioconnor

This comment has been minimized.

Show comment Hide comment
@guioconnor

guioconnor Jul 26, 2012

HI David, that explains. The Jade on your last comment is more or less how I'm doing it at the moment and it does work but this is not the same code as the original one because all you are doing is writing literal HTML for the opening tag. The original code, on the other hand, instructs Jade to create a <html> element that Jade automatically closes. Or am I missing something?

HI David, that explains. The Jade on your last comment is more or less how I'm doing it at the moment and it does work but this is not the same code as the original one because all you are doing is writing literal HTML for the opening tag. The original code, on the other hand, instructs Jade to create a <html> element that Jade automatically closes. Or am I missing something?

@davidsivocha

This comment has been minimized.

Show comment Hide comment
@davidsivocha

davidsivocha Aug 3, 2012

@guioconnor: The one from David is correct. By using literal tags it stops Jade from attempting to auto close the tag, like yours is doing.
You do need to remember to use a literal close at the end of your Jade document though.

@guioconnor: The one from David is correct. By using literal tags it stops Jade from attempting to auto close the tag, like yours is doing.
You do need to remember to use a literal close at the end of your Jade document though.

@arxpoetica

This comment has been minimized.

Show comment Hide comment
@arxpoetica

arxpoetica Oct 12, 2012

Here's another take using comments and literals: https://gist.github.com/3879867

Here's another take using comments and literals: https://gist.github.com/3879867

@jwerre

This comment has been minimized.

Show comment Hide comment
@jwerre

jwerre Dec 27, 2012

I recommend the following since jade renders a 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

jwerre commented Dec 27, 2012

I recommend the following since jade renders a 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
@ghepting

This comment has been minimized.

Show comment Hide comment
@ghepting

ghepting Apr 10, 2013

Nice improvement @jwerre -- have you attempted to remove the unwanted white space between these at all? I'm fairly confident there isn't really a way to do it, but if there is I'd love to find out as I'm completely OCD about stuff like that :)

Nice improvement @jwerre -- have you attempted to remove the unwanted white space between these at all? I'm fairly confident there isn't really a way to do it, but if there is I'd love to find out as I'm completely OCD about stuff like that :)

@kumarharsh

This comment has been minimized.

Show comment Hide comment
@kumarharsh

kumarharsh Jan 15, 2014

please do note that this behaviour has been ripped out of jade now...

visionmedia/jade#1345

Now, you have to just use this:

<!--[if lt IE 8]>
link(rel='stylesheet', href='style-ie8.css')
<![endif]-->

please do note that this behaviour has been ripped out of jade now...

visionmedia/jade#1345

Now, you have to just use this:

<!--[if lt IE 8]>
link(rel='stylesheet', href='style-ie8.css')
<![endif]-->
@yamsellem

This comment has been minimized.

Show comment Hide comment
@yamsellem

yamsellem Apr 28, 2014

Can you please define 'now'?
Which versions are concerned by the // IE 8 syntax and which are not?

Thanks.

Can you please define 'now'?
Which versions are concerned by the // IE 8 syntax and which are not?

Thanks.

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