Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:27:10+00:00 2026-06-12T23:27:10+00:00

How would I format HAML to output a style similar to the conditional HTML

  • 0

How would I format HAML to output a style similar to the conditional HTML tags used for cross-browser targeting?

<!doctype html>
<!--[if lt IE 8]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if IE 9]>    <html class="no-js ie9 oldie" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

If I add a conditional, it wraps entire page in the conditional as well. I thought about using HAML’s :plain filter at the top and manually adding </html> at the bottom, but this seems less than ideal to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:27:11+00:00Added an answer on June 12, 2026 at 11:27 pm

    The first three of these are pretty simple, as they are just plain HTML comments and you can use the Haml support for conditional comments:

    /[if lt IE 8] <html class="no-js ie7 oldie" lang="en">
    /[if IE 8] <html class="no-js ie8 oldie" lang="en">
    /[if IE 9] <html class="no-js ie9 oldie" lang="en">
    

    The last one is a bit different. Breaking it down, what you want is two comments surrounding the html opening tag, so the second comment is the first content of the html element. Also you can’t use the Haml syntax for conditional comments, you’ll have to use a literal comment. In Haml this would look like:

    <!--[if gt IE 9]><!-->
    %html{:class => 'no-js', :lang => 'en'}
      <!--<![endif]-->
    

    This will produce HTML like this:

    <!--[if gt IE 9]><!-->
    <html class='no-js' lang='en'>
      <!--<![endif]-->
    

    If you wanted you could use the whitespace removal syntax to make the generated HTML more like your example:

    <!--[if gt IE 9]><!-->
    %html{:class => 'no-js', :lang => 'en'}<>
      <!--<![endif]-->
    

    Putting it all together:

    !!!
    /[if lt IE 8] <html class="no-js ie7 oldie" lang="en">
    /[if IE 8] <html class="no-js ie8 oldie" lang="en">
    /[if IE 9] <html class="no-js ie9 oldie" lang="en">
    <!--[if gt IE 9]><!-->
    %html{:class => 'no-js', :lang => 'en'}<>
      <!--<![endif]-->
      content here
    

    which produces:

    <!DOCTYPE html>
    <!--[if lt IE 8]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
    <!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
    <!--[if IE 9]> <html class="no-js ie9 oldie" lang="en"> <![endif]-->
    <!--[if gt IE 9]><!--><html class='no-js' lang='en'><!--<![endif]-->
    content here</html>
    

    An alternative technique would be to use Haml’s surround helper:

    = surround "<!--[if gt IE 9]><!--><html class='no-js' lang='en'><!--<![endif]-->", "</html>" do
      content here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following schema / data / output how would I format a SQL
Which of Zotero's export format would you recommend regarding - the portability with similar
I'm making word frequency tables with R and the preferred output format would be
how would I format a datetime string received from MySQL? For example, when I
I would like to format some commands execution times in a human readable format,
I have a date and I would like to format the date like that:
I was trying to create an IFormatProvider implementation that would recognize custom format strings
I have a series of grouped values that follow a specific format and would
I would like to color format the text printed to the console using the
What would be the best format to numerically represent a color in .NET so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.