Significant Whitespace

GoHT templates and Haml are significant whitespace languages. This means that the indentation of the content is important.

Content that needs to be nested within an element is indented under that element.

Indentation

Indentation is used to indicate the structure of the content. The indentation creates the parent-child relationship of the elements.

%html
  %head
    %title= "Hello, World!"
  %body
    %h1= "Hello, World!"

renders as:

<html>
  <head>
    <title>Hello, World!</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

First line

The first line in a template must start at column one. After the first line, the indentation size and character are determined by the first significant whitespace before any content.

@goht MyTemplate() {
%p
  %span Hello, World!
}

Tabs or Spaces

You can use tabs or spaces for indentation. You can use any number of tabs or spaces for indentation. But you should be consistent. You should use either tabs or spaces for indentation and should not mix them.

The choice of tabs or spaces is up to you. It does not have an impact on the generation or the generated code. In fact, the generated code will be formatted using Go’s gofmt tool.

Nesting

You may only indent children one level below their parent. You may unindent as many levels as you need.

.main
  .header
    %h1
      Hello World!
  .content
    %p
      This is a paragraph.
.footer
  %p
    This is a footer.

In the above, each new indent, two spaces, was only one level deeper than the previous. The .header and .content are children of .main. We return from several indents to put the .footer at the same level as .main.