Haml :: SyntaxError-非法嵌套:不能同时将内容与%a放在同一行并嵌套在其中 [英] Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it

查看:84
本文介绍了Haml :: SyntaxError-非法嵌套:不能同时将内容与%a放在同一行并嵌套在其中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有HAML的Twitter Bootstrap中的按钮下拉菜单".在Bootstrap文档中,我找到了示例:

I'm using "Button dropdowns" from Twitter Bootstrap with HAML. In the Bootstrap docs I have found the example:

<div class="btn-group">
  <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
    Action
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <!-- dropdown menu links -->
  </ul>
</div>

我尝试使用HAML重写它:

I have tried rewrite it using HAML:

%div{:class => 'btn-group task_controller'}
  %a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action
    %span{:class => 'caret'}
  %ul{:class => 'dropdown-menu'}
    %a{:class => 'close_task', :name => task.name, :href => '#' } Close        

但收到错误消息:

Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it.

因此,Bootstrap说我将元素放在-tag内,但是HAML不允许这样做.我该如何解决该问题?

So Bootstrap said me put the element inside -tag, but HAML didn't allow to do it. How can I fix the problem?

推荐答案

问题出在以下几行:

%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action
  %span{:class => 'caret'}

错误消息:content can't be both given on the same line as %a and nested within it引用的内容Action与%a在同一行",而%span{:class => 'caret'}的内容嵌套在其中".

The error message: content can't be both given on the same line as %a and nested within it refers to Action which is content "on the same line as %a", and %span{:class => 'caret'}, which is content "nested within it".

更一般地讲,也许更容易看到,您不可能有这样的东西:

More generally, and perhaps easier to see, you can’t have something like this:

%tag Some content here
  And something here as well

解决方法是将两个嵌套在%a下:

The fix is to nest both under the %a:

%a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'}
  Action
  %span{:class => 'caret'}

这将提供所需的输出:

<a class='btn-mini dropdown-toggle' data-toggle='dropdown' href='#'>
  Action
  <span class='caret'></span>
</a>

这篇关于Haml :: SyntaxError-非法嵌套:不能同时将内容与%a放在同一行并嵌套在其中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆