Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAML in Rails 3 produces only doctype html

I am running into a problem:

If use something like this:

!!! XML
!!!
%html
  %head
    %title Myspace
  %body
    %h1 I am the international space station
    %p Sign my guestbook

I get only this as source:

<!DOCTYPE html>
<html>
  <head>
    <title>Myspace</title>
  </head>
  <body>

    <h1>I am the international space station</h1>
    <p>Sign my guestbook</p>
  </body>
</html>
like image 735
Unomagan Avatar asked Jan 25 '11 20:01

Unomagan


2 Answers

According to the HAML documentation, XHTML is the default DOCTYPE apart from for Rails 3 which uses HTML5. You can set the :format option to override.

In config/environment.rb:

Haml::Template.options[:format] = :xhtml
like image 188
John Topley Avatar answered Sep 26 '22 01:09

John Topley


For me it doesn't work to put it in environment.rb.

I set up an initializer in config/initializers/haml.rb and put in it...

Haml::Template.options[:format] = :xhtml

Be sure to restart the server after adding that.

Then in my pages...

!!! XML
!!!

This produces...

<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
like image 42
Ethan Avatar answered Sep 25 '22 01:09

Ethan