Static#home 中的 Haml::SyntaxError?

发布于 2024-09-05 22:22:25 字数 444 浏览 8 评论 0原文

我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

依 靠 2024-09-12 22:22:25

我认为它在抱怨,因为您在

标记内有一个

元素。 (代码中的第 4 行。)

I think it's complaining because you have a <p> element inside an <h1> tag. (Line 4 in your code.)

绿光 2024-09-12 22:22:25

您不能将内容放入标记行,同时添加嵌套内容。
正确代码:

#index-header
  %h1 Supersonic Mac Software.
  %p Some motto
%h1 
  Our Software
  %p Which will once becoume your's

You cannot put content in a tag line, and add nested content at the same time.
Correct code:

#index-header
  %h1 Supersonic Mac Software.
  %p Some motto
%h1 
  Our Software
  %p Which will once becoume your's
神经暖 2024-09-12 22:22:25

它会抱怨,因为您的内容与您的 %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.

不醒的梦 2024-09-12 22:22:25

如果您像我一样正在寻找解决方案,但却发现了一群唱反调的人。您会很高兴知道 HAML 完全有能力并且同样愿意满足此要求。

错误消息的重点在于单词在同一行,因为 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

您可能已经注意到,我们只需要更改一个具有嵌套 %p 标记的 %h1 定义,因为这是唯一违反 HAML 解析器的定义。

通过简单地将内容我们的软件移动到与其同行并排的缩进线上,我们有效地减少了认知摩擦,清楚地表明这两个项目是同一父项的兄弟姐妹。

以下代码片段将生成 bootstrap 3 样式页面标题

.page-header
  %h1
    Example page header
    %small Subtext for header

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.

#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

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

.page-header
  %h1
    Example page header
    %small Subtext for header

nJoy!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文