IE conditional statements in the Jade template engine

How to convert the following IE conditional expressions to the JADE language:

<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]--> <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]--> <!--[if !IE]><!--> <html lang="en"> <!--<![endif]--> 

I tried following, but it does not work:

 //if IE 8 html lang="en" class="ie8" //if IE 9 html lang="en" class="ie9" //if !IE html lang="en" // <![endif] 

The following output is shown:

 <!--if IE 8html lang="en" class="ie8" --> <!--if IE 9html lang="en" class="ie9" --> <!--if !IEhtml lang="en" --> <!-- <![endif]--> 

Can someone tell me how to fix this.

+6
source share
3 answers

Syntax support for conditional comment //if IE 8 was removed a few months ago: Git Commit <w> Version 0.35 was the latest version to support them; v1.0 is the first version after removal.


I use the literal style @Jayram; only differences are the conditional logic Γ  la h5bp and the closing html tag:

 | <!--[if IE 8]> <html lang="en" class="lt-ie9"> <![endif]--> | <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]--> 

Note. Remember to close the document with | </html> | </html> , since the original html tag is not Jade self-closing syntax.

+9
source

This code should work properly. It works with Jade version up to 0.35.0 .

Note that the last html element must be a valid Jade element (so attributes are in parentheses (...) ). The first two elements are parts of comments and therefore must be formed as formatted HTML elements.

 //if IE 8 <html lang="en" class="ie8"> //if IE 9 <html lang="en" class="ie9"> //[if !IE]><! html(lang="en") //<![endif] 

The output on the page is as follows:

 <!--[if IE 8]><html lang="en" class="ie8"><![endif]--> <!--[if IE 9]><html lang="en" class="ie9"><![endif]--> <!--[if !IE]><!--><html lang="en"><!--<![endif]--> 

EDIT

Starting with version 1.0.0 (released on December 22, 2013 ), Jade no longer parses comment content and does not support IE conditional comment support.

A new approach is to use IE's well-formatted conditional comments. This is safe, because now Jade ignores any line starting with < .

Your code may be as follows:

 <!--[if IE 8]><html class="ie8" lang="en"><![endif]--> <!--[if IE 9]><html lang="en" class="ie9"><![endif]--> <!--[if !IE]><!--> html(lang="en") <!--<![endif]--> 

Please note that the html element will be processed by Jade (with all its functions, for example, setting the class name from the request processing method), so you should NOT add | </html> | </html> at the end of your jade file.

You can also refer to IE conditional comments in the Jade Template Engine for an alternative to using Jade mixing with IE conditional comments.

I hope this helps.

+6
source

Use it like that. This works for me.

  | <!--[if IE 8]> <html lang="en" class="ie8"> <![endif]--> | <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]--> | <!--[if !IE]><!--> <html lang="en"> <!--<![endif]--> 
+2
source

All Articles