Conditional HTML tag in HAML

后端 未结 2 1952
野性不改
野性不改 2021-02-01 19:05

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



%html{:class => 'no-js', :lang => 'en'}
  

This will produce HTML like this:



  

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


%html{:class => 'no-js', :lang => 'en'}<>
  

Putting it all together:

!!!
/[if lt IE 8] 
/[if IE 8] 
/[if IE 9] 

%html{:class => 'no-js', :lang => 'en'}<>
  
  content here

which produces:






content here

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

= surround "", "" do
  content here

提交回复
热议问题