5

I am attempting to use the haml-jekyll-extension only I do not understand how to include yaml front matter? I have the following:

---
user: hello
---
!!!
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

but it ends up getting compiled into the following html:

user: hello
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
    <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>

How to do I mark the yaml front matter such that it gets compiled into html properly?

rudolph9
  • 8,021
  • 9
  • 50
  • 80
  • how are you viewing these files?... using a server (like jekyll server) or just opening the html file..? – Orlando May 06 '12 at 19:55
  • @landox sorry forget I posted this after I had figured it out, but it is a jekyll extension if you following the link, you use ejekyll and the extension converts the files when the server is launched. I think I may be able to convert it to a standard jekyll plugin though and not have to worry about ejekyll anymore but I figure that out eventually. – rudolph9 May 06 '12 at 20:02

2 Answers2

4

Use a back slash:

haml file:

\---
user: hello
\---
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

compiles into the following html:

---
user: hello
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
    <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>
rudolph9
  • 8,021
  • 9
  • 50
  • 80
  • There are two problems with this solution - 1) the front matter is printed in the output file and 2) you can't use nesting with YAML when you escape plain text with backslashes. – Andre Dickson Jul 08 '18 at 06:52
1

You can use Haml comments for front matter. This will let you use nesting in your YAML and it won't reproduce the front matter in your html. The following haml file

-#
  ---
  user: hello
  ---
!!!
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

will generate the following HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
   <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>
Andre Dickson
  • 111
  • 1
  • 4