【问题标题】:Illegal nesting in Haml在哈姆尔非法筑巢
【发布时间】:2011-12-05 20:31:07
【问题描述】:

这是我的 Haml 代码:

%html
  %head
  %body
    %table {'width' => 638, 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0}
      %tr
        %td {'width' => 27, 'height' => 100}
        %td {'width' => 582, 'height' => 100}
        %td {'width' => 29, 'height' => 100}

当我输入haml example.haml example.html 时,我收到以下错误:

Syntax error on line 5: Illegal nesting: content can't be both given on the same line as %table and nested within it.

我做错了什么?

【问题讨论】:

    标签: haml


    【解决方案1】:

    您需要删除标签和大括号之间的空格,如下所示:

    %html
      %head
      %body
        %table{'width' => 638, 'border' => 0, 'cellpadding' => 0, 'cellspacing' => 0}
          %tr
            %td{'width' => 27, 'height' => 100}
            %td{'width' => 582, 'height' => 100}
            %td{'width' => 29, 'height' => 100}
    

    【讨论】:

    • 另外,请注意,如果您正在使用普通属性,您可以使用 HTML-style attributes 来减轻您的打字负担,例如%td(width=27 height=100);每个属性少四个字符! :)
    【解决方案2】:

    如果其他人没有意识到自己犯了像我这样的错字,我想帮助他们避免非法嵌套的情况。

    如果你忘记了元素中的%,它会说非法嵌套

    p.small
      Some text!! Wow!!!!!!
    

    这将导致非法嵌套错误。不要忘记你的 %s!

    %p.small
      Some text that will actually view without errors, Profit!
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多