开发者

HAML in Rails 3 produces only doctype html

开发者 https://www.devze.com 2023-02-06 13:19 出处:网络
I am running into a problem: If use something like this: !!! XML !!! %html %head %title Myspace %body %h1 I am the international space stat开发者_JAVA百科ion

I am running into a problem:

If use something like this:

!!! XML
!!!
%html
  %head
    %title Myspace
  %body
    %h1 I am the international space stat开发者_JAVA百科ion
    %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>


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


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">
0

精彩评论

暂无评论...
验证码 换一张
取 消