Static#home 中的 Haml::SyntaxError?
我有这个 Haml:
#index-header
%h1 title
%p motto
%h1 Our Software
%p motto
.third-column
%h2 Product 1
%p foo
.third-column
%h2 Product 2
%p foo
.third-column
%h2 Product 3
%p foo
我收到此错误:
Static#home 中的 Haml::SyntaxError
显示 app/views/static/home.html.haml 第 5 行引发的位置:
非法嵌套:内容不能与 %h1 在同一行给出并嵌套在其中。
我做错了什么?谢谢。
I have this Haml:
#index-header
%h1 title
%p motto
%h1 Our Software
%p motto
.third-column
%h2 Product 1
%p foo
.third-column
%h2 Product 2
%p foo
.third-column
%h2 Product 3
%p foo
And I get this error:
Haml::SyntaxError in Static#home
Showing app/views/static/home.html.haml where line #5 raised:
Illegal nesting: content can't be both given on the same line as %h1 and nested within it.
What am I doing wrong? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为它在抱怨,因为您在
标记内有一个
元素。 (代码中的第 4 行。)
I think it's complaining because you have a
<p>
element inside an<h1>
tag. (Line 4 in your code.)您不能将内容放入标记行,同时添加嵌套内容。
正确代码:
You cannot put content in a tag line, and add nested content at the same time.
Correct code:
它会抱怨,因为您的内容与您的
%h1
标记(我们的软件
)位于同一行,并且嵌套在其下方(%p 它将成为您的
%p code>),就像错误消息所说的那样。It's complaining because you have content on the same line as your
%h1
tag (Our Software
) and nested beneath it (%p Which will once becoume your's
), just like the error message says.如果您像我一样正在寻找解决方案,但却发现了一群唱反调的人。您会很高兴知道 HAML 完全有能力并且同样愿意满足此要求。
错误消息的重点在于单词在同一行,因为 haml 需要将标签的所有内容缩进到其父标签下。
如果我们希望此问题的示例标记按指定方式工作,我们将对其进行如下修改以产生所需的结果,而无需进一步抱怨。
您可能已经注意到,我们只需要更改一个具有嵌套
%p
标记的%h1
定义,因为这是唯一违反 HAML 解析器的定义。通过简单地将内容
我们的软件
移动到与其同行并排的缩进线上,我们有效地减少了认知摩擦,清楚地表明这两个项目是同一父项的兄弟姐妹。以下代码片段将生成 bootstrap 3 样式页面标题
nJoy!
If you, like me, were looking for a solution, but found a choir of naysayers in chorus. You will be happy to know that HAML is completely capable and equally willing to accommodate this requirement.
The focus of the error message rests on the words on the same line as haml needs all the content of a tag to be indented under its parent.
If we wanted the the example markup from this question to work as specified, we modify it as follows to produce the desired results without further complaints.
You may have noticed, we only needed to change the one
%h1
definition which has the nested%p
tag, because this is the only definition violating HAML's parser.By simply moving the content
Our Software
to an indented line alongside its peers, we effectively reduce cognitive friction making it clear that both items are siblings of the same parent.The following snippet will produce the mark-up required for a bootstrap 3 styled page header
nJoy!