Read more

Conditional comments for Internet Explorer with Haml

Henning Koch
May 12, 2011Software engineer at makandra GmbH

Internet Explorer 5+ is aware of conditional comments Show archive.org snapshot that let you target HTML for selected versions of IE. For example the HTML below would ask users of IE 6 and IE 7 to install Firefox:

<!--[if lt IE 8]>
  <a href='http://www.mozilla.com/en-US/firefox/'>Get a real browser</a>
<![endif]-->
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

You might wonder how to express such a conditional comment in your favorite templating language, Haml Show archive.org snapshot . You might even have converted a template back to ERB just for this reason! But don't worry any longer, because Haml can do conditional comments Show archive.org snapshot :

/[if lt IE 8]
  %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }= 'Firefox'

Sometimes you may need to insert semi-conditional HTML that is ignored by IE but interpreted by real browsers, like:

<%= stylesheet_link_tag 'screen', :media => 'screen' %>

Such content cannot be expressed in Haml -- you need to open up an :erb section in your Haml file to put it there.

Posted by Henning Koch to makandra dev (2011-05-12 21:03)