HAML Indentation Issues

I am new to rails and haml .. and I cannot get this to work correctly.

I have this partial (_head.html.haml):

!!! %html %head %meta{'http-equiv' => 'Content-Type', :content => "text/html; charset=iso-8859-1"} = stylesheet_link_tag 'main' %body 

And then in my application application.html.haml:

 = render :partial => 'shared/head' #wrapperDIV = yield :layout 

But the result is not quite what I intend:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta content='text/html; charset=iso-8859-1' http-equiv='Content-Type' /> <link href="/stylesheets/main.css?1266030236" media="screen" rel="stylesheet" type="text/css" /> </head> <body></body> </html> <div id='wrapperDIV'></div> 

Obviously, <html> and <body> should wrap #wrapperDIV, but it seems that partial elements do not fall into the correct hierarchy.

+4
source share
2 answers

Particles are implicitly closed at the end. They must be full sub-objects.

Here is what you want:

 !!! %html %head %meta{'http-equiv' => 'Content-Type', :content => "text/html; charset=iso-8859-1"} = stylesheet_link_tag 'main' %body #wrapperDIV = yield :layout 

If you want to put your meta and stylesheet calls in partial, you can do this, but all the tags that you opened at the end of the haml document will be closed.

+4
source

html and body must be in application.html.haml

 !!! %html = render :partial => 'shared/head' %body #wrapperDIV = yield :layout 
+1
source

Source: https://habr.com/ru/post/1301235/